# floatify

> Common helper to floatify strings

Latest version **2.0.0** (published 2026-06-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install floatify
pnpm add floatify
yarn add floatify
bun add floatify
```

## Health

**Score 55/100 (C)** — status: active.

Positive: esm support; no vulnerabilities; high maintenance score.

Warnings: low downloads; no types.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-06-02 |
| First published | 2019-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >= 18.0.0 |
| Dependencies | 0 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | pocketrocket |
| Maintainers | pocketrocket |
| Keywords | floatify, float, string, convert, decimals, localization, numbers |

## Links

- npm: https://www.npmjs.com/package/floatify
- Repository: https://github.com/pocketrocket/floatify
- Homepage: https://github.com/pocketrocket/floatify#readme
- Issues: https://github.com/pocketrocket/floatify/issues
- npm.io page: https://npm.io/package/floatify

## Alternatives

- [random-seedable](https://npm.io/package/random-seedable.md) — 27.9K weekly downloads
- [n2words](https://npm.io/package/n2words.md) — 22.2K weekly downloads
- [@stdlib/math-base-special-factorialln](https://npm.io/package/@stdlib/math-base-special-factorialln.md) — 5.7K weekly downloads
- [@stdlib/math-base-special-abs2](https://npm.io/package/@stdlib/math-base-special-abs2.md) — 1.7K weekly downloads
- [commons-math-interpolation](https://npm.io/package/commons-math-interpolation.md) — 1.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2026-06-02
- 1.4.0 — 2019-05-25
- 1.3.0 — 2019-02-28
- 1.2.2 — 2019-02-28
- 1.2.1 — 2019-02-22
- 1.2.0 — 2019-02-22
- 1.1.1 — 2019-02-22
- 1.1.0 — 2019-02-21
- 1.0.1 — 2019-02-21
- 1.0.0 — 2019-02-21

## README

# floatify

> 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.

## Installation

```sh
npm i floatify
```

## Usage

`floatify` is an **ES module** that exports a single function as the default export:

```js
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.7568
```

### Prefer decimal over thousands separator

By default an ambiguous single separator is treated as a **thousands**
separator. Pass `true` as the second argument to prefer a **decimal** point:

```js
floatify("123.123");        //=> 123123   (thousands, default)
floatify("123.123", true);  //=> 123.123  (decimal)
```

See `test/floatify.js` for the full set of supported formats.

## Requirements

- **Node.js ≥ 18** (pure ESM, no transpiler required).

## Breaking changes

### v2.0.0
- **ESM-only.** `floatify` is now a native ES module (`export default`).
  Import it with `import floatify from "floatify"` — `require()` is no longer
  supported (use Node ≥ 22.12 `require(esm)` if you must consume it from CJS).
- Modernised to ES6+ and migrated to the built-in Node test runner; no runtime
  dependencies.

### v1.3.0
- `floatify` exports the function directly: call `floatify(str)` instead of
  `floatify.floatify(str)`.

## Development

```sh
npm test     # node --test
npm run lint # eslint
```

## License

[MIT](LICENSE)

---
_Source: https://npm.io/package/floatify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
