Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function roundPadded(n, d = 0) {
- const div = Math.pow(10, d)
- let res = (Math.round(n * div) / div).toString().split('.')
- const whole = res[0]
- if (d <= 0) {
- return whole
- }
- let dec = res[1] || ''
- if (d > 0 && dec.length < d) {
- dec += '0'.repeat(d - dec.length)
- }
- return whole + '.' + dec
- }
Add Comment
Please, Sign In to add comment