Pages: [1]   Go Down
 Author Topic: Get units, 10ths and 100ths of a value  (Read 209 times) 0 Members and 1 Guest are viewing this topic.
Nova Scotia
Offline
Full Member
Karma: 2
Posts: 119
 « on: November 21, 2012, 01:47:37 pm » Bigger Smaller Reset

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
 Logged

Massachusetts, USA
Offline
Tesla Member
Karma: 96
Posts: 6335
 « Reply #1 on: November 21, 2012, 01:54:46 pm » Bigger Smaller Reset

How can I see the 2 and the 1?

You mean: "t = t/10;"

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

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

Alternatively:
Code:
int ones = t%10;
int tens = (t/10)%10;
int hundreds = (t/100)%10;
int thousands = (t/1000)%10;
 Logged

Netherlands
Offline
Tesla Member
Karma: 86
Posts: 9360
In theory there is no difference between theory and practice, however in practice there are many...
 « Reply #2 on: November 21, 2012, 02:10:42 pm » Bigger Smaller Reset

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

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

 Pages: [1]   Go Up