Version: v0.7.1 - Beta.  We welcome contributors & feedback.

Number.zeroPad

zeroPad($numLeftDigits, $numDecimalDigits = 0) -> string

Description

Add zeros to the left of a number so that its length is equal to $numLeftDigits.

If $numDecimalDigits is given, add zeros to the right of the decimal point.

Returns a string.

(123).zeroPad(5)    //= '00123'
(123).zeroPad(2)    //= '123'

(123.4).zeroPad(5)  //= '00123'

(123).zeroPad(5, 2)     //= '00123.00'
(123.56).zeroPad(5, 3)  //= '00123.560'

See Also