Floating Point Precision
This is because of the IEEE Standard for Floating-Point Arithmetic. I ended up down this rabbit hole to better understand it, but ultimately I decided to work around it.
Quick Solution: Convert Floats Into Integers
So to break this down, we first needed these to be whole numbers and if we divide by 100 again. The first example we get will return with a decimal in the hundredths. However, what if there were zeros in place of .99? Any trailing zeros will not appear. This is fine until the end result for the user to see. This doesn't work completely because it needs to be set to the hundredths place. This is where
toFixed comes in.
But! There is a useful constructor that can do all of the formatting better than what I demonstrated.
So take the last example from above and disregard
toFixed entirely. Not only does this help with decimal format, but also handles segmenting by commas and provides the correct currency symbol. It's also preferred if your client's site sells outside of the US as it can sync with localization. It also handles more than formatting for currency as well. I highly recommend using this, as it will save you many headaches.
If you're wanting to see how IEEE-754 works, here are the following resources: