Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Formatting a number with exactly two decimals in JavaScript
- One way to be 100% sure that you get a number with 2 decimals:
- (Math.round(num*100)/100).toFixed(2)
- If this causes rounding errors, you can use the following as James has explained in his comment:
- (Math.round((num * 1000)/10)/100).toFixed(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement