---
url: /docs/guide/usage/linter/rules/unicorn/prefer-number-coercion.md
---

### What it does

Prefer `Number()` over `parseFloat()` and base-10 `parseInt()`.

### Why is this bad?

`parseFloat()` and `parseInt()` parse numeric prefixes and ignore trailing text.
`Number()` parses the full input, which better matches intent when coercing values.

### Examples

Examples of **incorrect** code for this rule:

```javascript
const value = parseFloat(input);
const integer = parseInt(input, 10);
```

Examples of **correct** code for this rule:

```javascript
const value = Number(input);
const integer = Math.trunc(Number(input));
```

## How to use

## Version

This rule was added in v1.71.0.

## References
