Skip to content

Commit d037c59

Browse files
authored
Merge pull request eugenp#5197 from vaibs28/master
BAEL-2152
2 parents 9842e35 + c98a023 commit d037c59

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.baeldung.decimalformat;
2+
3+
import java.math.RoundingMode;
4+
import java.text.DecimalFormat;
5+
import java.text.NumberFormat;
6+
import java.util.Locale;
7+
8+
public class DoubletoString {
9+
10+
public static void main(String[] args) {
11+
12+
double doubleValue = 345.56;
13+
14+
System.out.println(String.valueOf((int) doubleValue));
15+
16+
System.out.println(String.format("%.0f", doubleValue));
17+
18+
doubleValue = Math.floor(doubleValue);
19+
DecimalFormat df = new DecimalFormat("#");
20+
df.setRoundingMode(RoundingMode.FLOOR);
21+
System.out.println(df.format(doubleValue));
22+
23+
Locale enlocale = new Locale("en", "US");
24+
String pattern = "###,##";
25+
df = (DecimalFormat) NumberFormat.getNumberInstance(enlocale);
26+
df.applyPattern(pattern);
27+
String format = df.format(doubleValue);
28+
System.out.println(format);
29+
30+
Locale dalocale = new Locale("da", "DK");
31+
df = (DecimalFormat) NumberFormat.getNumberInstance(dalocale);
32+
df.applyPattern(pattern);
33+
System.out.println(df.format(doubleValue));
34+
35+
36+
}
37+
38+
}

0 commit comments

Comments
 (0)