I'm programming a microcontroller in C and since the compiler or chip doesn't handle Floating Point numbers very well, it is recommended to scale the floating point value up enough to get rid of the decimal and then when outputting the number, scale it back down with a proportional division and use modulus to find and display the fractional part. Here's an example:
Start with number 25.0625
. Multiply by 10000
to get 250625
. Good now we don't have a float anymore. Now to display this we use a line like this:
sprintf(buffer, "%li.%i", Temp / 10000, abs(Temp % 10000));
So we first get the 25
back out by / 10000
, then we get the 0625
out by % 10000
. Here's the problem though: It appears my modulus result ignores the leading zero in 0625 so when it concatenates the number back together, it becomes 25.625
instead of 25.0625
. I can't count on there always being a leading zero, so stuffing a zero in there isn't the answer, and there could at other times be several leading zeros. My question is, how do I suppress the modulus from excluding leading zeros ? Thanks.