0

I don't understand the double variable, how the answer is not 0.1??

plz check out my code and give me an answer https://code.sololearn.com/cUiNS7iT48F7/?ref=app

15th Oct 2021, 9:54 AM
RLB
RLB - avatar
2 Antworten
+ 6
Numbers with decimal can't be represented accurately due to floating point airthmetic. https://www.google.com/url?sa=t&source=web&rct=j&url=https://docs.microsoft.com/en-us/cpp/build/why-floating-point-numbers-may-lose-precision%23:~:text%3DFloating%252Dpoint%2520decimal%2520values%2520generally,operations%2520may%2520produce%2520unexpected%2520results.&ved=2ahUKEwi48Ovlm8zzAhWBbn0KHeC_AQUQFnoECAQQBQ&usg=AOvVaw21fOyKmXMcnhXoPVpKuX_G
15th Oct 2021, 10:37 AM
Abhay
Abhay - avatar
+ 4
RLB Doubles and floats, such joys they bring to mortal man. Try this approach instead double a=100.1; a = (a*10 - 1000)/10; Console.WriteLine(a);
15th Oct 2021, 11:23 AM
Rik Wittkopp
Rik Wittkopp - avatar