-
Notifications
You must be signed in to change notification settings - Fork 1
ToNumber
ricardoboss edited this page Sep 13, 2023
·
1 revision
toNumber
converts a string to a number.
toNumber(string value, number radix = 10)
-
value
: The string to convert to a number. -
radix
: The radix to use when converting the string to a number. Defaults to10
. Supported are2
,8
,10
and16
.
- If
value
cannot be converted to a number,null
is returned. - If
radix
is not supported,null
is returned. - If
radix
is not specified,10
is used. -
value
is parsed using C#s InvariantCulture. This means the decimal separator is.
and the group separator is,
. - only a
radix
of10
can parse a decimal number. All otherradix
es will parse the number as an integer.
toNumber("123") // 123
toNumber("123", 10) // 123
toNumber("1.23") // 1.23
toNumber("1,23") // 123
toNumber("FF", 16) // 255
toNumber("FF", 10) // null
toNumber("9", 8) // null
toNumber("1010", 2) // 10
toNumber("1010.01", 2) // 10
© 2023 Ricardo Boss • Licensed under MIT • Want to update this page? Edit it on GitHub and submit a pull request!