Variable floatConst

float: Simple.Parser<number> = ...

Parse floats.

Remarks

Example

  run(float("123"))       => Ok(123)
run(float("3.1415")) => Ok(3.1415)
run(float("0.1234")) => Ok(0.1234)
run(float(".1234")) => Ok(0.1234)
run(float("1e-42")) => Ok(1e-42)
run(float("6.022e23")) => Ok(6.022e23)
run(float("6.022E23")) => Ok(6.022e23)
run(float("6.022e+23")) => Ok(6.022e23)

If you want to disable literals like .123 (like in Elm) you could write something like this:

  elmFloat : Parser Float
elmFloat =
oneOf
[ symbol "."
|. problem "floating point numbers must start with a digit, like 0.25"
, float
]

Note: If you want a parser for both Int and Float literals, check out number below. It will be faster than using oneOf to combining int and float yourself.