Guest User

Untitled

a guest
Feb 17th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. function roundPadded(n, d = 0) {
  2. const div = Math.pow(10, d)
  3. let res = (Math.round(n * div) / div).toString().split('.')
  4. const whole = res[0]
  5. if (d <= 0) {
  6. return whole
  7. }
  8. let dec = res[1] || ''
  9. if (d > 0 && dec.length < d) {
  10. dec += '0'.repeat(d - dec.length)
  11. }
  12. return whole + '.' + dec
  13. }
Add Comment
Please, Sign In to add comment