When I perform a truncate using:
label.setText(String.format("%.2f", 1.2975118));
// 1,30
I get comma(,) instead of point(.) and this causes my program crash since I need to perform operation on float numbers.
How I can truncate a float and .setText
with a point instead of comma?
Please be careful as String.format depend on your current Local configuration, you may not get a dot as a separator.
Prefer using String.format(java.util.Locale.US,"%.2f", floatValue);
Locale independent :
double d = 1.234567;
DecimalFormat df = new DecimalFormat("#.##");
System.out.print(df.format(d));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With