Common helper to floatify strings — locale-aware string → float parsing.
floatify turns a numeric string into a Number, automatically guessing the
thousands and decimal separators (., , or space) regardless of locale.
It returns NaN for ambiguous or invalid input.
npm i floatifyfloatify is an ES module that exports a single function as the default export:
import floatify from "floatify";
floatify("123123.245346556");
//=> 123123.245346556
floatify("123.242,5346556");
//=> 123242.5346556
floatify("123,242.5346556");
//=> 123242.5346556
floatify("123 242 123.7568");
//=> 123242123.7568By default an ambiguous single separator is treated as a thousands
separator. Pass true as the second argument to prefer a decimal point:
floatify("123.123"); //=> 123123 (thousands, default)
floatify("123.123", true); //=> 123.123 (decimal)See test/floatify.js for the full set of supported formats.
- Node.js ≥ 18 (pure ESM, no transpiler required).
- ESM-only.
floatifyis now a native ES module (export default). Import it withimport floatify from "floatify"—require()is no longer supported (use Node ≥ 22.12require(esm)if you must consume it from CJS). - Modernised to ES6+ and migrated to the built-in Node test runner; no runtime dependencies.
floatifyexports the function directly: callfloatify(str)instead offloatify.floatify(str).
npm test # node --test
npm run lint # eslint