Merge pull request #5197 from vaibs28/master

BAEL-2152
This commit is contained in:
daoire 2018-09-09 20:17:56 +01:00 committed by GitHub
commit d037c59c3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,38 @@
package com.baeldung.decimalformat;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
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));
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));
}
}