Add a fromString static method on Num that converts strings to numbers.
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
IO.print(Num.fromString("123") == 123) // expect: true
|
||||
IO.print(Num.fromString("-123") == -123) // expect: true
|
||||
IO.print(Num.fromString("-0") == -0) // expect: true
|
||||
IO.print(Num.fromString("12.34") == 12.34) // expect: true
|
||||
IO.print(Num.fromString("-0.0001") == -0.0001) // expect: true
|
||||
|
||||
// Test a non-number literal and ensure it returns null.
|
||||
IO.print(Num.fromString("test1") == null) // expect: true
|
||||
@@ -6,5 +6,5 @@ IO.print(-0) // expect: -0
|
||||
IO.print(123.456) // expect: 123.456
|
||||
IO.print(-0.001) // expect: -0.001
|
||||
|
||||
// TODO: Hex? Scientific notation?
|
||||
// TODO: Scientific notation?
|
||||
// TODO: Literals at and beyond numeric limits.
|
||||
|
||||
Reference in New Issue
Block a user