Updates to Double to string
@@ -3,7 +3,6 @@ package com.baeldung.decimalformat;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
- import java.util.Locale;
public class DoubletoString {
@@ -15,24 +14,16 @@ package com.baeldung.decimalformat;
System.out.println(String.format("%.0f", doubleValue));
+ NumberFormat nf = NumberFormat.getInstance();
+ nf.setMaximumFractionDigits(0);
+ nf.setRoundingMode(RoundingMode.FLOOR);
+ System.out.println(nf.format(doubleValue));
+
doubleValue = Math.floor(doubleValue);
- DecimalFormat df = new DecimalFormat("#");
+ DecimalFormat df = new DecimalFormat("#,###");
df.setRoundingMode(RoundingMode.FLOOR);
System.out.println(df.format(doubleValue));
- Locale enlocale = new Locale("en", "US");
- String pattern = "###,##";
- df = (DecimalFormat) NumberFormat.getNumberInstance(enlocale);
- df.applyPattern(pattern);
- String format = df.format(doubleValue);
- System.out.println(format);
-
- Locale dalocale = new Locale("da", "DK");
- df = (DecimalFormat) NumberFormat.getNumberInstance(dalocale);
- df.applyPattern(pattern);
- System.out.println(df.format(doubleValue));
-
-
}
}
