Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Conversion Precision #1128

Answered by Brunni
davidkappelt asked this question in Q&A
Discussion options

When converting certain values such as 328.999mV to V (which is a base unit), the answer adds a bit of error resulting in 0.32899900000000004.

Looking at the code I am a bit confused as to why this occurs. Any clarification would be very helpful.

You must be logged in to vote

This is caused by the normal double precision: https://en.wikipedia.org/wiki/Double-precision_floating-point_format

If you write 328.999d / 1000 in a normal c# code you will get the same error. This is just how floating point in computers work.

To avoid this in c# code it is possible to use decimal instead: 328.999m / 1000

Replies: 1 comment

Comment options

This is caused by the normal double precision: https://en.wikipedia.org/wiki/Double-precision_floating-point_format

If you write 328.999d / 1000 in a normal c# code you will get the same error. This is just how floating point in computers work.

To avoid this in c# code it is possible to use decimal instead: 328.999m / 1000

You must be logged in to vote
0 replies
Answer selected by angularsen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /