C++ Precision: String to Double

前端 未结 2 657
轻奢々
轻奢々 2021-01-06 06:45

I am having a problem with precision of a double after performing some operations on a converted string to double.

#include    
#include <         


        
2条回答
  •  甜味超标
    2021-01-06 07:28

    The "problem" here is simply that 34.38 cannot be exactly represented in double-precision floating point. You should read this article which describes why it's impossible to represent decimal values exactly in floating point.

    If you were to examine "34.38 * 100" in hex (as per "format hex" in MATLAB for example), you'd see:

    40aadc0000000001
    

    Notice the final digit.

提交回复
热议问题