[Solved] How can I find the amount of numbers in double?

[ad_1]

This won’t end up well. The problem is that sometimes there are float errors when representing numbers in binary (which is what your computer does).
For example, when adding 1 / 3 + 1 / 3 + 1 / 3 you might get 0.999999… and the number of decimal places varies greatly.

ravi already provided a good way to calculate it, so I’ll provide a different one:

double number = 0; // should be equal to the number you want to check
int  numFloating = 0;
while ((double)(int)number != number){
    number *= 10;
    numFloating++;
}

number is a double variable that holds the number you want to check for decimal places.

3

[ad_2]

solved How can I find the amount of numbers in double?