JSFiddle - React, Tailwind, and code Playground
JavaScript
//Add by adding a prototype to the number data structure
Number.prototype.toFixedDown = function(digits) {
//generate a regex which checks for -ve numbers also.
var re = new RegExp("([-]*\\d+\\.\\d{" + digits + "})(\\d)"),
//try matching the regex with the number supplied.
m = this.toString().match(re);
//return result accordingly
return m ? parseFloat(m[1]) : this.valueOf();
};
//helper
function show(d) {
console.log(d);
}
var x = 1.00000000000999;
show(x.toFixedDown(2));