-
Hello,
In my c++ code,
I expect bond_fc to be 502080.7, but it is 502081. Looks like strtod is responsible for that. I wonder how to avoid this unwanted rounding to the nearest int value. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The value is not rounded to nearest int value - the tool you're using to print/view the value is truncating it.
Single precision floating point numbers can't represent decimals exactly in general, but also have little decimal precision left for large numbers, so the value above has an error (when represented as floats) of ~0.0125. If that error is significant, you can always use double instead. |
Beta Was this translation helpful? Give feedback.
The value is not rounded to nearest int value - the tool you're using to print/view the value is truncating it.
Single precision floating point numbers can't represent decimals exactly in general, but also hav…