Description

Analyze if a char is a digit (that is a number). Returns true if the input char is a number.

Syntax

Use the following function to evaluate a char variable:

isDigit(thisChar)

Parameters

The function admits the following parameter:

thisChar: char variable to evaluate. Allowed data types: char.

Returns

The function returns true if the evaluated input variable is a number.

Example Code

char myChar = '8'; // try with 'n' for a non numerical char

void setup() {
  Serial.begin(9600);

  if (isDigit(myChar)) {  // tests if myChar is a digit
    Serial.println("The character is a number");
  }
  else {
    Serial.println("The character is not a number");
  }
}

void loop() {
}

See also