ParseFloat () vs parseDouble ()

I am trying to execute the code below to convert a string to float and double, but get different results.

the code:

 System.out.println(Float.parseFloat("120059389"));
 System.out.println(Double.parseDouble("120059389"));

Output:

1.20059392E8
1.20059389E8

Can someone explain to me why I got a different result for parsing a string in float and double? What are the ranges for float and double?

+4
source share
3 answers

, float, , . "ulp" ( ) float, 8.0, "ulp" double - . , float 8, double .

System.out.println(Math.ulp(120059389f));
System.out.println(Math.ulp(120059389d));

:

8.0
1.4901161193847656E-8

, float float 120059389, 1.20059392E8.

+10

, Double Float -.

, Double Double , Float.

, , - Float Double Float .

  • Float: 32-
  • Double: 64-

, Float, .

...

Float 1 (-/+), 8 23 .

Double 1 (-/+), 8 53 .

120059389 = 111001001111111010111111101b, 27 , Double 53 , Float 23 , .

, 23 1.20059392 = 111001001111111011000000000b, .

+6

. "laymans" , float 32 , double - 64 . , - . , , 32- "float". 64- "" .

, 64- 128 .

+1
source

Source: https://habr.com/ru/post/1535791/


All Articles