chickadee » scheme » string->number

string->number stringprocedure
string->number string radixprocedure

Returns a number of the maximally precise representation expressed by the given string. Radix must be an exact integer. The R5RS standard only requires implementations to support 2, 8, 10, or 16, but CHICKEN allows any radix between 2 and 36, inclusive. If supplied, radix is a default radix that may be overridden by an explicit radix prefix in string (e.g. "#o177"). If radix is not supplied, then the default radix is 10. If string is not a syntactically valid notation for a number, then string->number returns #f.

(string->number "100")                ===>  100
(string->number "100" 16)             ===>  256
(string->number "1e2")                ===>  100.0
(string->number "15##")               ===>  1500.0

Note: The domain of string->number may be restricted by implementations in the following ways. String->number is permitted to return #f whenever string contains an explicit radix prefix. If all numbers supported by an implementation are real, then string-> number is permitted to return #f whenever string uses the polar or rectangular notations for complex numbers. If all numbers are integers, then string->number may return #f whenever the fractional notation is used. If all numbers are exact, then string->number may return #f whenever an exponent marker or explicit exactness prefix is used, or if a # appears in place of a digit. If all inexact numbers are integers, then string->number may return #f whenever a decimal point is used.

As an extension to R5RS, CHICKEN supports reading and writing the special IEEE floating-point numbers +nan, +inf and -inf, as well as negative zero.