Go Down

### Topic: Get units, 10ths and 100ths of a value (Read 2083 times)previous topic - next topic

#### 0miker0

##### Nov 21, 2012, 07:47 pm
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

#1
##### Nov 21, 2012, 07:54 pm

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: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

#### robtillaart

#2
##### Nov 21, 2012, 08:10 pm

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