Pages: [1]   Go Down
Author Topic: Get units, 10ths and 100ths of a value  (Read 815 times)
0 Members and 1 Guest are viewing this topic.
Nova Scotia
Offline Offline
Full Member
***
Karma: 4
Posts: 204
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset 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 Offline
Tesla Member
***
Karma: 212
Posts: 8967
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 223
Posts: 13896
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset 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 -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: