I’m having trouble getting my answer to return in the correct format for currency. I’ve learned about the toFixed() method so you can use .toFixed(2) to display 50 cents as ["0.50"] but it’s a string and it’s supposed to be a number format like [0.50] for your answer.
If I convert to a number with
var change = 0.5;
Number(change.toFixed(2))
Results back to displaying 0.5 . I’ve also tried Number.parseFloat() but anytime I convert to a number it drops the zero off the end.
Is there an easy way to simply display as a number with an extra decimal place?
Thank you in advance for any help with this!!
-Todd
I had this same problem. While I couldn’t find a way to make the trailing zeroes stay in a non-string form, as I thought was required, I was able to pass the test. I did so by switching out .toFixed() with Math.round() in the function I used to make the answer array. Once they were real numbers the tests passed, even though they weren’t formatted like the ‘should return’ sections of the test cases.
I was stuck on this for hours, what with this and javascripts floating point weirdness.
Yes. It was a while back that I finished it but I think as long as the format is a number value and not a string it works. The lack of zeroes on the end didn’t matter, as long as everything else was right.