From 2cb97dbe49d1b8f9f7571219685f1a3dec776efd Mon Sep 17 00:00:00 2001 From: Marcin Krykowski Date: Mon, 25 May 2020 09:06:54 +0100 Subject: [PATCH] Add exception throwing to withDecimalFormatPattern() method --- .../src/main/java/com/baeldung/formatNumber/FormatNumber.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/java-numbers/src/main/java/com/baeldung/formatNumber/FormatNumber.java b/java-numbers/src/main/java/com/baeldung/formatNumber/FormatNumber.java index 4ce93adae0..a9925dee9d 100644 --- a/java-numbers/src/main/java/com/baeldung/formatNumber/FormatNumber.java +++ b/java-numbers/src/main/java/com/baeldung/formatNumber/FormatNumber.java @@ -50,8 +50,10 @@ public class FormatNumber { DecimalFormat df3 = new DecimalFormat("#,###,###,##0.000"); if (places == 2) return new Double(df2.format(value)); - if (places == 3) + else if (places == 3) return new Double(df3.format(value)); + else + throw new IllegalArgumentException(); } public static double withDecimalFormatLocal(double value) {