-
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.
Answered by
zeux
Sep 10, 2022
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.
1 reply
Answer selected by
masrul
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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…