9 lines
250 B
TypeScript
9 lines
250 B
TypeScript
// @ts-strict-ignore
|
|
export function toFixed(num: string | number, fixed: number) {
|
|
if (num === "" || num === null) {
|
|
return "";
|
|
}
|
|
|
|
const re = new RegExp("^-?\\d+(?:.\\d{0," + (fixed || -1) + "})?");
|
|
return num.toString().match(re)[0];
|
|
}
|