digit-value(3scm) Scheme Programmer's Manual digit-value(3scm)

digit-value - get the numeric value of a character

(import (scheme char))              ;R7RS

(digit-value char)

This procedure returns the numeric value of its argument if it is a numeric digit or #f on any other character. Numeric digits are those for which char-numeric? returns #t. Only the numeric values 0 to 9 are supported; characters representing other values are non-numeric.

Returns a single value; an exact integer or #f.

(digit-value #\3)      =>  3
(digit-value #\x0664)  =>  4    ;if supported
(digit-value #\x0AE6)  =>  0    ;if supported
(digit-value #\x0EA6)  =>  #f   ;if supported

Implementations are not required to support characters other than ASCII (excluding #\null). Therefore only the characters #\0 to #\9 need to be supported. Even implementations with full Unicode support may return #f for some characters that other implementations support, because the Unicode standard changes over time.

It is an error if the wrong number of arguments was passed or an argument was outside its domain. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

string->number(3scm), char-general-category(3scm), char-numeric?(3scm)

R7RS

This procedure first appeared in R7RS.

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://weinholt.se/scheme/manpages/.

2023-03-21