Hello. I’ve definitely hit rounding issues. My code passes all the tests other than the fifth one. I end up with 3 cents rather than 4 cents and so ‘Insufficient Funds’ is returned. Any ideas? Thanks.
I guess the Math.round() is causing this, because it rounds to an integer. You can avoid this by using something like this: Math.round(someValue*100)/100 to round to hundredths.
Thanks for looking. I’ve just realised I meant to use Math.floor. That gets me closer to the solution - I don’t get the $2 now. But rounding errors are now definitely causing the test to fail - I end up with 3 cents rather than 4 cents and so I get ‘Insufficient Funds’ returned. * 100 / 100 doesn’t seem to help.
It sounds like what you’re encountering is floating point precision in JavaScript. Sometimes when you’re working with decimals you’ll get some strange results unless you perform mathematical operation that might be between decimal numbers a certain way.