Module

Data.Number

Functions for working with PureScripts builtin Number type.

#fromString

fromString :: String -> Maybe Number

Attempt to parse a Number using JavaScripts parseFloat. Returns Nothing if the parse fails or if the result is not a finite number.

Example:

> fromString "123"
(Just 123.0)

> fromString "12.34"
(Just 12.34)

> fromString "1e4"
(Just 10000.0)

> fromString "1.2e4"
(Just 12000.0)

> fromString "bad"
Nothing

Note that parseFloat allows for trailing non-digit characters and whitespace as a prefix:

> fromString "  1.2 ??"
(Just 1.2)

#isFinite

isFinite :: Number -> Boolean

Test whether a number is finite

Modules