tc39 / proposal-number-fromstring

{BigInt,Number}.fromString(string, radix)
https://mathiasbynens.github.io/proposal-number-fromstring/
65 stars 7 forks source link

fractional part #23

Open yukulele opened 8 months ago

yukulele commented 8 months ago

Is fractional part allowed? example:


Number.fromString('3.14159', 10) // => 3.14159
Number.fromString('100.11', 2) // => 4.75
Number.fromString('202.1', 3) // => 20.33333333333333
Number.fromString('ff.4', 16) // => 255.25
ljharb commented 8 months ago

The readme says

It accepts only strings that can be produced by {BigInt,Number}.prototype.toString(radix = 10), and throws an exception for any other input.

so since eg 4.75.toString(2) === '100.11' then yes, those should all work.

yukulele commented 8 months ago

that's what I assumed, but as the readme only gives examples with integers, it's not very obvious.

yukulele commented 4 months ago

dot (.) is not mentioned in spec:

  1. If string represents a mathematical number value in radix-R notation, using the characters 0-9 for digits with values 0 to 9, and the letters a-z for digits with values 10 through 35, then