Procedure: number->string z [radix]
The procedure
number->stringtakes a number and a radix and returns as a string an external representation of the given number in the given radix such that(let ((number number) (radix radix)) (eqv? number (string->number (number->string number radix) radix)))is true. It is an error if no possible result makes this expression true.
If present,
radixmust be an exact integer in the range 2 to 36, inclusive. If omitted,radixdefaults to 10.If
zis inexact, theradixis 10, and the above expression can be satisfied by a result that contains a decimal point, then the result contains a decimal point and is expressed using the minimum number of digits (exclusive of exponent and trailing zeroes) needed to make the above expression; otherwise the format of the result is unspecified.The result returned by
number->stringnever contains an explicit radix prefix.Note: The error case can occur only when
zis not a complex number or is a complex number with a non-rational real or imaginary part.Rationale: If
zis an inexact number and theradixis 10, then the above expression is normally satisfied by a result containing a decimal point. The unspecified case allows for infinities, NaNs, and unusual representations.
Procedure: string->number string [radix]
Returns a number of the maximally precise representation expressed by the given
string. It is an error ifradixis not an exact integer in the range 2 to 26, inclusive.If supplied,
radixis a default radix that will be overridden if an explicit radix prefix is present in the string (e.g."#o177"). Ifradixis not supplied, then the defaultradixis 10. 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.0 (string->number "#x100" 10) ⇒ 256