Matching Excel's floating point in Java

后端 未结 6 1219
长发绾君心
长发绾君心 2020-12-11 02:06

I have an .xlsx spreadsheet with a single number in the top-left cell of sheet 1.

The Excel UI displays:

-130.98999999999

This is v

6条回答
  •  囚心锁ツ
    2020-12-11 02:27

    Unfortunately, this is not the same number the user can see in Excel. Can anyone point me to an algorithm to obtain the same number the user sees in Excel?

    I don't think that it is using an algorithm here. Excel uses IEEE754 double internally and I'd guess that it is just using a printf style format when displaying the number:

    $ python -c 'print "%.14g" % -130.98999999999069' 
    -130.98999999999
    
    $ python -c 'print "%.14g" % -130.9899999999907' 
    -130.98999999999
    

提交回复
热议问题