Skip to content
On this page

toNumber

Converts a string which contains a number into the number itself.

Usage

ts
import { toNumber } from '@screaming/utils'

toNumber('1234')
// 1234

toNumber('$1,234')
// 1234

toNumber('-12.34%')
// -12.34

toNumber('ribbit')
// NaN
1
2
3
4
5
6
7
8
9
10
11
12
13

Type Definitions

ts
/**
 * @param str - The string.
 * @returns The number.
 */
export declare function toNumber(str: string): number
1
2
3
4
5