You can design an algorithm with consecutive multiplication of the number by 10 until you obtain a decimal remain of zero, something like:
// asumming number is positive, extra code needed to handle negatives
int decimalDigits(double number) // or float
{
int decimals = 0;
while (number-floor(number) > 0.0) {
number *= 10.0;
decimals++;
}
return decimals;
}
Main Topics
Browse All Topics





by: KashraPosted on 2004-05-29 at 05:21:53ID: 11186794
I'm not sure that there is a difference in the underlying representation between:
1.132000
and
1.1320
So my guess would be no. Unless you're reading the values from user input (or a file) and have the option of reading the values as a string instead of an integer/float.