I'm trying to work out how to round a decimal to .49 or .99.
I have found the toFixed(2) function, but not sure how to round up or down.
Basically need to get to the closest price point, so for example X.55 would go down to X.49 and X.84 would go up to X.99.
This doesn’t require jQuery but can be done with plain JavaScript:
Math.round(price*2)/2 - 0.01
Note to also consider the case where the number would get rounded to 0 (price > 0.25) as that would yield -0.01 in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With