sprintf error...?

I've noticed that sprintf seems to round the whole number part of doubles incorrectly. The below code loads string 's' with a value that seems to be rounded down to the closest 100 Hz. This causes my app grief, and I sure wish I could figure out how to use sprintf to print all the digits to the left of the decimal point correctly. Anyone have any advice on this question...?

#define CRYSTAL (20000000.0)
#define MUL (1401.0)
#define DIV (255.0)
#define MCK (CRYSTAL*(MUL+1.0)/(DIV*2.0))

double fClock = MCK; // debugger shows fClock as 54980392

sprintf(s,"%1.0f",fClock); // incorrectly loads s with "54980400"

The funny thing is that I can use sprintf to load strings with "%11.09f" as the format string, and it's right 9 places to the right of the decimal point. I just can't figure out why it can't handle the integer part of double precision floating point numbers as well.

Thanks,
Seadog.

Parents Reply Children
No data
More questions in this forum