BAEL-2152

code snippet for converting double to String
This commit is contained in:
Vaibhav Sahay 2018-09-05 19:09:31 +05:30 committed by GitHub
parent bfb333d57f
commit 0da07de99e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
package com.baeldung.doubletostring;
import java.math.RoundingMode;
import java.text.DecimalFormat;
public class DoubletoString {
public static void main(String[] args) {
double doubleValue = 345.56;
System.out.println(String.valueOf((int) doubleValue));
System.out.println(String.format("%.0f", doubleValue));
doubleValue = Math.floor(doubleValue);
DecimalFormat df = new DecimalFormat("#");
df.setRoundingMode(RoundingMode.FLOOR);
System.out.println(df.format(doubleValue));
}
}