Skip to content

Commit 0da07de

Browse files
authored
BAEL-2152
code snippet for converting double to String
1 parent bfb333d commit 0da07de

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎core-java/DoubletoString.java‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.baeldung.doubletostring;
2+
3+
import java.math.RoundingMode;
4+
import java.text.DecimalFormat;
5+
6+
public class DoubletoString {
7+
8+
public static void main(String[] args) {
9+
10+
double doubleValue = 345.56;
11+
12+
System.out.println(String.valueOf((int) doubleValue));
13+
14+
System.out.println(String.format("%.0f", doubleValue));
15+
16+
doubleValue = Math.floor(doubleValue);
17+
DecimalFormat df = new DecimalFormat("#");
18+
df.setRoundingMode(RoundingMode.FLOOR);
19+
System.out.println(df.format(doubleValue));
20+
21+
}
22+
23+
}

0 commit comments

Comments
 (0)