Arduino Forum
>
Using Arduino
>
Programming Questions
>
Get digits of integer
Print
Go Down
Pages:
[1]
Topic: Get digits of integer
(Read 648 times)
previous topic

next topic
stoopkid
Sr. Member
Posts: 446
Karma: 3
[add]
Nick Gardner
Get digits of integer
Mar 11, 2011, 09:03 am
If I have an integer, how to I see how many digits it is, and how to I grab single numbers from certain places? Like the number 45, how do I get that it is 2 digits, and how do I ask for the first digit to get 4 and the second digit to get 5?
thanks
cvdg
Guest
Re: Get digits of integer
#1
Mar 11, 2011, 10:13 am
The integer 45 is not the same as the number 45.
The first is used for calculation, the second is only used for display and are 2 characters: '4' and '5'.
int a= 45 / 10 // a = 4
int b = 45 % 10 // b = 5
Use the same construction if you want 100, 1000, etc.
stoopkid
Sr. Member
Posts: 446
Karma: 3
[add]
Nick Gardner
Re: Get digits of integer
#2
Mar 11, 2011, 10:57 am
cool, thanks
Print
Go Up
Pages:
[1]
Loading...