How to form a number to have 10 decimal places? [closed]

-1

I have a sum operation and I have to display the result in a number with 10 decimal places precision. Any ideas?

    
asked by anonymous 30.05.2017 / 01:45

2 answers

1

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:

example - ideone

double number = 1.11111111111111111+1.11111111111111111;
String value = String.format("Dez números após o decimal: %1$.10f",
        number);
System.out.println(value);

example - ideone

    String result = String.format("%.10f", 10.3333333333333333 + 3.33333333333333333);
    System.out.println (result);
    
30.05.2017 / 02:56
1
 String value = String.format("Dez casas decimais: %1$.10f",10/3d);
 System.out.println(value);
    
30.05.2017 / 01:54