Truncate a decimal value in C++

后端 未结 10 1735
萌比男神i
萌比男神i 2020-12-10 05:38

What\'s the easiest way to truncate a C++ float variable that has a value of 0.6000002 to a value of 0.6000 and store it back in the variable?

10条回答
  •  渐次进展
    2020-12-10 06:04

    A good reference for why this happens can be found in What Every Computer Scientist Should Know About Floating Point Arithmetic by David Goldberg.

提交回复
热议问题