Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision |
functions:atof [2017/04/17 15:08] – korshun | functions:atof [2017/04/17 15:32] – korshun |
---|
If s is too big or too small to fit into a fixed-point number, returns [[constants:INT_MAX]] with the sign of the input. | If s is too big or too small to fit into a fixed-point number, returns [[constants:INT_MAX]] with the sign of the input. |
| |
Supports [[:Number prefixes]]. | Supports signs and [[:Number prefixes]]. |
| |
<note important>This function parses the fractional part only up to the amount of digits that can be stored in a fixed-point number. This means that numbers with very long fractional parts will not be fully parsed, e.g. ''%%"0.12345678901234567890thisisnotanumberanymore!@#$^#$^$*%^*$"%%'' will parse successfully. | <note important>This function parses the fractional part only up to the amount of digits that can be stored in a fixed-point number. This means that numbers with very long fractional parts will not be fully parsed, e.g. ''%%"0.12345678901234567890thisisnotanumberanymore!@#$^#$^$*%^*$"%%'' will parse successfully. |
</note> | </note> |
| |
| <note tip>To parse ints, use [[atoi]].</note> |
| |
===== Examples ===== | ===== Examples ===== |
| |
<code> | <code> |
atoi("123") -> 123 | atof("123") -> 123.0 |
atoi("0") -> 0 | atof("123.456") -> 123.456 |
atoi("999999999999") -> 2147483647 // Too big | atof("0") -> 0 |
atoi("-99999999999") -> -2147483647 // Too small | atof("999999999999") -> 32767.99999 // Too big |
atoi("not a number") -> 0 // Error | atof("-99999999999") -> -32767.99999 // Too small |
atoi("1.3") -> 0 // Error | atof("not a number") -> 0 // Error |
atoi("0xff") -> 255 // Hexadecimal prefix | atof("0xff.8") -> 255.5 // Hexadecimal prefix |
</code> | </code> |
| |