Pages: [1]   Go Down
Author Topic: Get digits of integer  (Read 371 times)
0 Members and 1 Guest are viewing this topic.
California
Offline Offline
Sr. Member
****
Karma: 3
Posts: 433
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Papendrecht, NL
Offline Offline
Newbie
*
Karma: 1
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

California
Offline Offline
Sr. Member
****
Karma: 3
Posts: 433
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

cool, thanks
Logged

Pages: [1]   Go Up
Jump to: