+ 1

Why is the output so wrong.?

I was just wondering why does the output of this code not just 0.3 , I thought I just found out some bug with python language but it shows the same output if I try different languages. Whats the reason of such output and if there's a reason why (0.2+0.3) gives output 0.5 and not as it does in the inserted code. https://code.sololearn.com/cG53FUl3WbDw/?ref=app

26th Aug 2021, 12:27 AM
ADITYA KHANDELWAL
ADITYA KHANDELWAL - avatar
4 Answers
+ 6
https://www.sololearn.com/Discuss/2836796/?ref=app
26th Aug 2021, 12:41 AM
Simba
Simba - avatar
0
i know this isnt really an answer. i just wanted to bring this up. i think this problem can be solved by multiplying the decimals by 100, then add the two, and divide by a hundred.
26th Aug 2021, 1:28 AM
you are smart. you are brave.
you are smart. you are brave. - avatar
0
But how could it be corrected? I've made two codes that seems to do this: #1 k1 = lambda flt: (flt * 10 ** 8) // 1 / 10 ** 8 #2 k2 = lambda flt: float(f"{flt:.8f}") # This won't work for every case of floating-point error
26th Aug 2021, 6:15 AM
Calvin Thomas
Calvin Thomas - avatar