@cstan/only-numeric
v2.0.2
Published
Filters out all non-numeric characters from string
Downloads
8
Readme
only-numeric
A Common JS package that has a string for the first argument and the second (optional) argument is boolean. If you use a decimal POINT (period) as a decimal marker the second arg should be true (absent second argument defaults to true), if you use a decimal COMMA as a decimal marker the second argument should be false.
Installation:
npm install @cstan/only-numeric
Use:
const { onlyNumeric } = require("@cstan/only-numeric")
let s = "- $USD 1,234.56";
let n = onlyNumeric(s);
console.log(`The number is: ${n}`);
// -1234.56
OR
let s = " EU - 1.234,56";
let n = onlyNumeric(s, false); // Note: false added as second argument
console.log(`The number is: ${n}`);
// -1234,56