-1
I have a sum operation and have to display the result in a number with 10 decimal places of accuracy. Any idea?
-1
I have a sum operation and have to display the result in a number with 10 decimal places of accuracy. Any idea?
1
String value = String.format("Dez casas decimais: %1$.10f",10/3d);
System.out.println(value);
Nice answer Rovann, but it would be interesting to explain a little your code so that it is more clear.
is a normal float, result of splitting 2 int.
1
We use "f" to indicate a floating point. Before that, we specify ". 10" to mean "Ten numbers after 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);
Browser other questions tagged java
You are not signed in. Login or sign up in order to post.
What have you tried? Add your code to the question,
– user28595
It depends on what that number is. It’s a monetary value or something?
– Maniero
is a float resulting from splitting 2 int.
– Sabrina
Splitting 2 int does not result in a float type. Please add your code by editing the question, to make it easier for us to understand its difficulty.
– user28595