So given a double, how would I determine its width without the decimals? For example 100.1111, should be a width of 3 for 100. or 1.1 should just be 1.
So given a double, how would I determine its width without the decimals? For example 100.1111, should be a width of 3 for 100. or 1.1 should just be 1.
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Actually how would I use this function? Do I just simply replace arr with doub?
And how do I declare the array?Code:for (unsigned i = 0; i != sizeof(arr)/sizeof(arr[0]); ++i) { std::cout << arr[i] << ' ' << static_cast<unsigned>(std::log10(arr[i])) + 1 << '\n'; }
That is what I did but its giving me an arr not declared error.Code:for (unsigned i = 0; i != sizeof(doub)/sizeof(arr[0]); ++i) { cout << arr[i] << ' ' << static_cast<unsigned>(log10(arr[i])) + 1 << '\n'; }
Last edited by dnguyen1022; 01-19-2009 at 01:00 PM.
That code is simply to show the lenght in digits of each number in arr[]. You have a vector with your squared numbers, so you need to figre the length of those. The part that does static_cast<unsigned>(std::log10(...) is what you need - the rest is just to walk through the testing array - which is not what you want to do.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Oh, okay so I was able to get the length, but its giving me 1 less than the actualy length which I believe is why there is a + 1 in the example code. Is this correct?
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
Alright, I know how to deal with it if its a negative number. Thanks for your help!