Hi,
For an integer say 123456, how do i extract the rightmost 3 digits (456) from that integer?
thx
Printable View
Hi,
For an integer say 123456, how do i extract the rightmost 3 digits (456) from that integer?
thx
you could try a string approach
http://msdn.microsoft.com/library/de...acmausitow.asp
Code:int x = 123456;
int y = x % 1000;
//Now y is 456
thx!Quote:
Originally Posted by XSquared
Oh modulus the beautiful.... Xsquared beat me to it.
Code:#include <vector>
...
...
vector <int> breakdown(int number)
{
vector<int> buffer;
while(true)
{
if(number / 10 == 0)
{
buffer.push_back(number);
break;
}
buffer.push_back(number % 10);
number /= 10;
}
return buffer;
}