How do I convert a 2 digit number into 2 numbers

I want to convert a 2 digit fahrenheit reading to 2 numbers eg 6,5 so i can send data to 7 segment leds

I am using the led-matrix library - but I am not happy with the way I am getting values....

Does anyone know the best way to "chomp" this data?

int digit1 = number / 10;
int digit2 = number % 10;

:slight_smile:

Mikal

You must live in a cold climate if the temperature never gets above 99 degrees F :wink:

If you ever do need to convert more digits, this routine can be expanded to any number of digits:

#define MAX_DIGITS 3
int val = 23; // test with value of 23
int digits[MAX_DIGITS];

for(int i=0; i < MAX_DIGITS; i++){
digits = val %10;

  • val = val / 10;*
  • }[/font]*
    The digits are placed in the digits array. digits[0] is the least significant digit. A temperature of 123 would set the digit elements to values of: 3,2,1