 # GPU compute problem in compute shader

Hi!
I would like to print a number to a texture, the problem is that I’ve imprecision problem, in fact, when I want to display this number :

double number = 45896.8579;
drawNumber(ivec2(0, resolution.y-1), 1, vec4(1, 0, 0, 1), number);

I got 45896.859375 instead of 45896.8579.

I extract the digits of the decimal part like this :

double rest = fract(number);
if (rest > 0) {
drawPunt(position, nbPixels, color);
position.x += digitSpacing;
do {
rest *= 10;
int digit = int(rest);
rest -= digit;
drawDigit(position, nbPixels, color, digit);
position.x += digitSpacing;
} while (rest != 0);
}

it should work like this :

rest = 8.579, digit = 8.
rest = 8.579 - 8 = 0.579.
rest = 5.79 digit = 5.
rest = 5.79 - 5 = 0.79.
rest = 7.9, digit = 7 or I get 9!!! So it’s the conversion from double to int which is not correct or it’s rest*10 which is not correct or it’s 5.79 - 5 which is not correct!

I think it’s simply imprecision problem because of binary representation of float/double, so I need to correct this imprecision problem but I don’t know how, but anyway it was just for debuging so if it’s approximative it’s ok.