number/#/pad.js
raw| 1 | "use strict"; |
| 2 | |
| 3 | var pad = require("../../string/#/pad") |
| 4 | , toPosInt = require("../to-pos-integer") |
| 5 | , toFixed = Number.prototype.toFixed; |
| 6 | |
| 7 | module.exports = function (length /*, precision*/) { |
| 8 | var precision; |
| 9 | length = toPosInt(length); |
| 10 | precision = toPosInt(arguments[1]); |
| 11 | |
| 12 | return pad.call( |
| 13 | precision ? toFixed.call(this, precision) : this, "0", |
| 14 | length + (precision ? 1 + precision : 0) |
| 15 | ); |
| 16 | }; |