c# - Is double Multiplication Broken in .NET? -


this question has answer here:

if execute following expression in c#:

double = 10*0.69; 

i is: 6.8999999999999995. why?

i understand numbers such 1/3 can hard represent in binary has infinite recurring decimal places not case 0.69. , 0.69 can represented in binary, 1 binary number 69 , denote position of decimal place.

how work around this? use decimal type?

because you've misunderstood floating point arithmetic , how data stored.

in fact, code isn't performing arithmetic @ execution time in particular case - compiler have done it, saved constant in generated executable. however, can't store exact value of 6.9, because value cannot precisely represented in floating point point format, 1/3 can't precisely stored in finite decimal representation.

see if this article helps you.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -