string->number -- r7rs Definition converter;
string->number (from vonuvoli);Procedure variants:
((string-empty) -> (false))
string-empty;false;((string-not-empty) -> (number-or-false))
string-not-empty;number-or-false;((string-empty number-radix) -> (false))
string-empty;number-radix;false;((string-not-empty number-radix) -> (number-or-false))
string-not-empty;number-radix;number-or-false;scheme:base -- (scheme base);scheme -- (scheme);(string->number string) (string->number string radix)Returns a number of the maximally precise representation expressed by the given
string.Domain: It is an error if
radixis not2,8,10, or16.If supplied,
radixis a default radix that will be overridden if an explicit radix prefix is present instring(e.g."#o177"). Ifradixis not supplied, then the default radix is10. Ifstringis not a syntactically valid notation for a number, or would result in a number that the implementation cannot represent, thenstring->numberreturns#f. An error is never signaled due to the content ofstring.(string->number "100") ===> 100 (string->number "100" 16) ===> 256 (string->number "1e2") ===> 100.0Note: The domain of
string->numbermay be restricted by implementations in the following ways. If all numbers supported by an implementation are real, thenstring->numberis permitted to return#fwheneverstringuses the polar or rectangular notations for complex numbers. If all numbers are integers, thenstring->numbermay return#fwhenever the fractional notation is used. If all numbers are exact, thenstring->numbermay return#fwhenever an exponent marker or explicit exactness prefix is used. If all inexact numbers are integers, thenstring->numbermay return#fwhenever a decimal point is used.Note: The rules used by a particular implementation for
string->numbermust also be applied toreadand to the routine that reads programs, in order to maintain consistency between internal numeric processing, I/O, and the processing of programs. As a consequence, the R5RS permission to return#fwhenstringhas an explicit radix prefix has been withdrawn.
The text herein was sourced and adapted as described in the "R7RS attribution of various text snippets" appendix.