floating point - Why do I see a double variable initialized to some value like 21.4 as 21.399999618530273? -


double r = 11.631; double theta = 21.4; 

in debugger, these shown 11.631000000000000 , 21.399999618530273.

how can avoid this?

these accuracy problems due internal representation of floating point numbers , there's not can avoid it.

by way, printing these values @ run-time still leads correct results, @ least using modern c++ compilers. operations, isn't of issue.


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -