+ 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
4 Answers
+ 6
https://www.sololearn.com/Discuss/2836796/?ref=app
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.
0
similar questions was asked yesterday have a look
https://www.sololearn.com/Discuss/2865768/?ref=app
https://www.sololearn.com/discuss/1288636/?ref=app
https://www.sololearn.com/discuss/374762/?ref=app
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