Precise floating-point<->string conversion

后端 未结 5 495
误落风尘
误落风尘 2020-12-09 05:03

I am looking for a library function to convert floating point numbers to strings, and back again, in C++. The properties I want are that str2num(num2str(x)) == x and that nu

5条回答
  •  無奈伤痛
    2020-12-09 05:34

    Actually I think you'll find that 1.34 IS 1.3400000000000001. Floating point numbers are not precise. You can't get around this. 1.34f is 1.34000000333786011 for example.

提交回复
热议问题