I have a sum operation and I have to display the result in a number with 10 decimal places precision. Any ideas?
I have a sum operation and I have to display the result in a number with 10 decimal places precision. Any ideas?
We use "f" to denote a floating point. Before that, we specified ".10" to mean "Ten numbers after the decimal." example - ideone
double number = 1.23456789;
String value = String.format("Dez números após o decimal: %1$.10f",
number);
System.out.println(value);
Examples using sum of two numbers:
double number = 1.11111111111111111+1.11111111111111111;
String value = String.format("Dez números após o decimal: %1$.10f",
number);
System.out.println(value);
String result = String.format("%.10f", 10.3333333333333333 + 3.33333333333333333);
System.out.println (result);
String value = String.format("Dez casas decimais: %1$.10f",10/3d);
System.out.println(value);