function toFixed(num, fixed) {
var re = new RegExp('^-?\\d+(?:\.\\d{0,' + (fixed || -1) + '})?');
return num.toString().match(re)[0];
}
Example
toFixed(1.05, 1) //1.0
toFixed(1.05, 0) //1
function toFixed(num, fixed) {
var re = new RegExp('^-?\\d+(?:\.\\d{0,' + (fixed || -1) + '})?');
return num.toString().match(re)[0];
}
Example
toFixed(1.05, 1) //1.0
toFixed(1.05, 0) //1
Comments