java - Why does float print only up to 8 Digits? -


when printing below statement

system.out.println(121.3456422f); 

i getting output 121.34564 (in 8 digits)

and if printing

system.out.println(121345642.333332f); 

i getting output 1.2134564e8 (in 10 digits including e)

i want know why float 8 digits only?

the default conversion of float string produces shortest decimal fraction convert float on input. 8 decimal digits, because float has 24 bits of effective significand.

the exact value of 121.3456422f 121.34564208984375. largest float smaller 121.34563446044921875. 121.34564 between values , closer original value alternative, 8 enough digits.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -