+ 1

Why is final_price = price *1.07 different from final_price = price *107/100

Was doing the ballpark orders problem using python. My code worked in first two cases, but hidden cases failed. A Google search found this as a possible fix and sure enough it now passed. It must be a rounding issue?

30th Jan 2022, 10:38 AM
Gareth Vaughan
Gareth Vaughan - avatar
3 odpowiedzi
+ 2
Yep. Rounding error. Even though BODMAS/PEMDAS says it shouldn't matter, it does. Seems that division causes rounding issues when performed anywhere except last. I think I had to add the tax to the total separately to pass test case #5.
30th Jan 2022, 11:29 AM
HungryTradie
HungryTradie - avatar
+ 1
Wierd. Thank you.
30th Jan 2022, 9:28 PM
Gareth Vaughan
Gareth Vaughan - avatar
0
It confuse me now. and I also curious about how to google it. thanks
17th Mar 2022, 2:15 PM
wenyu