Count number of digits after `.` in floating point numbers?

I doubt this is what you want since the question is asking for something that’s not usually meaningful with floating point numbers, but here is the answer:

int digits_after_decimal_point(double x)
{
    int i;
    for (i=0; x!=rint(x); x+=x, i++);
    return i;
}

Leave a Comment