Hi there
is there anyway of counting how long an integer is, using something like strlen, since I dont think that works with integers
e.g. 100000000
is 9 characters long
would appreciate any help
Hi there
is there anyway of counting how long an integer is, using something like strlen, since I dont think that works with integers
e.g. 100000000
is 9 characters long
would appreciate any help
Convert it to a string and use strlen()
By the way, the example number you gave was too big to be a regular int. Make it a long int.
for ints, use itoa(), for longs, ltoa(). The usage is:
itoa(num, string, 10);
where the last parameter is always "10" if you are using the base-10 (normal) number system.
Last edited by Sebastiani; 11-20-2001 at 10:06 AM.
Code:#include <cmath> #include <complex> bool euler_flip(bool value) { return std::pow ( std::complex<float>(std::exp(1.0)), std::complex<float>(0, 1) * std::complex<float>(std::atan(1.0) *(1 << (value + 2))) ).real() < 0; }
That depends on the o/s. 32 bit o/s's will use 32 bit ints, allowing signed values up to 2147483647.By the way, the example number you gave was too big to be a regular int.
zen
Here's another way. Credit goes to someone who posted this on the old board.
Code:int numlen(int n) { //get the length of a integer this will work for the length of longs also //but this function will not work with floats or doubles because of the decimal point. return (log10(n)+1); }