Go Down

Topic: Get units, 10ths and 100ths of a value (Read 1 time) previous topic - next topic

0miker0

How can I get break up and integer to get the 100ths or 1000value?

int t= 1234

int a = t % 10;  //get units
//I see a value on the serial monitor of 4

x = x/10;
int b = t % 10; // get tens value
//I see a value on the serial monitor of 3

How can I see the 2 and the 1?

Mike

johnwasser


How can I see the 2 and the 1?


You mean: "t = t/10;"

Code: [Select]

t = t/10;
int c = t % 10; // get hundreds value

t = t/10;
int d = t % 10; // get thousands value


Alternatively:
Code: [Select]

int ones = t%10;
int tens = (t/10)%10;
int hundreds = (t/100)%10;
int thousands = (t/1000)%10;
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

robtillaart


I prefer the last solution of John as it keeps the original value of t
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy