From d4d4a0e1a408eb9a2d9924101de37ab7919ec861 Mon Sep 17 00:00:00 2001 From: Sam Gardner Date: Wed, 11 Oct 2023 11:09:45 +0100 Subject: [PATCH] BAEL-6895 extend String format test to cover negatives --- .../baeldung/truncatedouble/TruncateDoubleUnitTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/truncatedouble/TruncateDoubleUnitTest.java b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/truncatedouble/TruncateDoubleUnitTest.java index d5881c5d66..1bbca4069f 100644 --- a/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/truncatedouble/TruncateDoubleUnitTest.java +++ b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/truncatedouble/TruncateDoubleUnitTest.java @@ -61,9 +61,13 @@ public class TruncateDoubleUnitTest { @Test public void givenADouble_whenUsingStringFormat_truncateToTwoDecimalPlaces() { - double value = 1.55555555; - String truncated = String.format("%.2f", value); + double positive = 1.55555555; + String truncated = String.format("%.2f", positive); assertEquals("1.56", truncated); + + double negative = -1.55555555; + String negativeTruncated = String.format("%.2f", negative); + assertEquals("-1.56", negativeTruncated); } }