# How to Convert a String to a Number in JavaScript

DevFeed: [How to Convert a String to a Number in JavaScript](<https://devfeed.tech/articles/how-to-convert-a-string-to-a-number-in-javascript-106037.md>)

Original publisher: [Read original article](<https://markodenic.com/javascript-string-to-number/>)

Author: Marko

Published: 2026-10-28T20:00:00Z

Content type: article

Language: en

Sources: [Marko Denic Blog](<https://devfeed.tech/sources/marko-denic-blog.md>)

Topics: [JavaScript](<https://devfeed.tech/topics/javascript.md>), [concatenation](<https://devfeed.tech/topics/concatenation.md>)

Tags: [bigint](<https://devfeed.tech/tags/bigint.md>), [comparison](<https://devfeed.tech/tags/comparison.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [money](<https://devfeed.tech/tags/money.md>), [number](<https://devfeed.tech/tags/number.md>), [plus](<https://devfeed.tech/tags/plus.md>), [string](<https://devfeed.tech/tags/string.md>), [table](<https://devfeed.tech/tags/table.md>), [tutorial](<https://devfeed.tech/tags/tutorial.md>), [web-development](<https://devfeed.tech/tags/web-development.md>)

## AI overview

Use `Number(str)` for a strict conversion of the whole string: it returns `NaN` for trailing units, but turns empty or whitespace-only strings into `0`, so handle those separately and validate with `Number.isFinite()`. Use `parseInt(str, 10)` or `parseFloat(str)` to read a number from the start of text with units; `parseInt` truncates decimals, while `parseFloat` keeps them. Unary plus behaves like `Number()`. The article also advises `array.map(Number)` instead of `array.map(parseInt)`, notes JavaScript's basic parsing does not handle locale grouping separators, and recommends `BigInt` or strings for integers beyond the safe-number range. For money, it suggests integer cents because decimal arithmetic can be inexact.

## Source excerpt

Convert a string to a number in JavaScript with Number(), parseInt(), parseFloat() and unary plus. Which one to use, a comparison table of edge cases, and how to validate, handle BigInt and money.