daily pastebin goal
18%
SHARE
TWEET

Untitled

a guest Feb 17th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top