Lox Nexus

Class: StringToNumber

Lenient number parsing for strings from other systems: "20%" -> 0.2, "20.5€" -> 20.5, "1.234,5" -> 1234.5, "1,234,567" -> 1234567, "2_000" -> 2000. Anything unparseable becomes 0.

With only one kind of separator, a single separator is a decimal point ("0.125" -> 0.125, "12,5" -> 12.5). It is read as digit grouping only when it repeats ("1.234.567"). The old converter treated "0.125" as 125.

Constructors

Constructor

new StringToNumber(): StringToNumber

Returns

StringToNumber

Methods

parse()

parse(input): number

Parameters

input

string

Returns

number

the parsed number; a trailing % divides by 100. Never throws and never returns NaN or Infinity, 0 is the answer for anything that does not look like a number.