android - How to display decimal numbers in Java? -


this question has answer here:

i'm using float display decimal numbers, doesn't display correct result.

for example, 6.2/1000 result 0.0061999997.

i know why happening, wonder there way display correct result, in case, 0.0062?

edit: how round number n decimal places in java not answer question, why did marked question been answered in other place?

numbers wrote example. in app user can enter number , divide / multiply number other number, result maybe won't have decimal points, maybe have 4 decimals, maybe have 7 decimals,...

first, need understand isn't display issue - if want avoid displaying incorrect values, helps have right values start with.

you should use bigdecimal instead of float. stores value integer scaled factor of 10exp rather 2exp used double , float.

if bigdecimal.tostring doesn't format result way want, use decimalformat perform formatting instead.


Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -