English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2 answers

the easy way is, get floor value of the given number, which is number before decimal.

then substract as given number - floor number is number after decimal.

2006-09-16 18:21:34 · answer #1 · answered by Anonymous · 0 0

Finding the number of digits before the decimal point is easy - log10() function will do the job.
The number of digits _after_ the decimal point is tricky. The fact, that a number is 1.5 rather than 1.499999999999 is a happenstance, defined by the particular platform and compiler.

You may take your chances with the following:

float your_floating_number;
int result;
char string[25];
sprintf(string, "%f", your_floating_number);
result = strlen(strchr(string,'.')) - 1;

2006-09-16 18:31:08 · answer #2 · answered by alex_self 2 · 0 0

fedest.com, questions and answers