import { Meta, Source } from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/functional-basic/Functions/toNumber - Converting a value to a number'/>

# `toNumber`

Converts a string or number into a finite floating-point number. The function is designed to handle various formatting styles, including thousands separators and different decimal markers.

**Parameters:**
- `value?: NumberOrString` — The input value for conversion.

**Returns:**
`number` — The parsed float number or `0` if conversion fails or the value is non-finite.

## Examples

<Source
  language='typescript'
  code={`
import { toNumber } from '@dxtmisha/functional-basic'

// 1. Handling various separators
toNumber('1 250,50')       // 1250.5
toNumber('1,000,000.99')   // 1000000.99
toNumber('1.250,50')       // 1250.5

// 2. Stripping non-numeric characters
toNumber('abc-12.5')       // -12.5
toNumber('$1,234.56')      // 1234.56

// 3. Numbers and special values
toNumber(123.45)           // 123.45
toNumber(-0)               // 0 (normalized)
toNumber(Infinity)         // 0
toNumber(undefined)        // 0
  `}
/>
