parse_float
fn parse_float(string s) -> Result<float, string> Import
Source: use conv::{parse_float}; src/conv.hy Parses a decimal float such as "3.5", "-0.25", "1e3" or "42".
Surrounding ASCII whitespace, a sign and an exponent (e or E) are accepted.
Parameters#
| Name | Type |
|---|---|
s | string |
Returns#
Result<float, string>
Errors#
Err("invalid float") when s is not a number.
Examples#
use conv::{parse_float};
use tests::assert;
assert!((parse_float("2.5") ?? 0.0) == 2.5);
assert!((parse_float("1e3") ?? 0.0) == 1000.0);
assert!(parse_float("abc").is_err());
See also#
int_to_dec: Formatsnin decimal; the same asformat("%i", n).int_to_hex: Formatsnin lowercase hexadecimal without a prefix; a negativengets a leading-.int_to_bin: Formatsnin binary without a prefix; a negativengets a leading-.parse_int_radix: Parses an integer written in baseradix, which must be 10 or 16.parse_int: Parses a decimal integer, such as"42"," -7 "or"+3".