Re: how to determine how many digits there are in a number after the decimal point?
Quote:
Originally Posted by Usul
But hey, I solved it and it works.
Yes it does and the reason is the defined rounding (as I mentioned in #11). By doing this you're working with exact numbers in the decimal number system. The "fuzziness" the decimal-binary conversions introduce disappears in the rounding.
Re: how to determine how many digits there are in a number after the decimal point?
Quote:
Originally Posted by Usul
ok, this works (if you are interested)
That's a lot of code for something you can do like:
Code:
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
unsigned int getDigitsAfterDecimalPoint(double number)
{
ostringstream o;
o << number;
size_t dotpos = o.str().find('.');
return (dotpos == string::npos ? 0 : o.str().find_last_not_of('0') - dotpos);
}