Guest
#659434
Hello,
I have a very curious problem with float arithmetics:
When I use the following code
float variable;
variable = 12.0;
printf ("%f", variable);
printf (lcd_putc, "%f", variable);
the output on both the display and the RS232 is 11.9999999
This wouldn't be a problem, but in my application, I only need one
number after the comma.
So I use
printf ("%4.1f", variable);
and the "12.0" which becomes "11.9999999" appears as "11.9" !!!!!
Isn't there any function for outputting variables which doesn't just
"cut" the variable to the desired length like %4.1f but which rounds to
the last significant number?
So if the number is 11.99999, the program recognizes that after 11.9
there is a 9 following, so the number is rounded to 12.0.
Just like rounding in mathematics is done. Not just ignoring the numbers
after the desired range.
It's a pity that I couldn't find any rounding function within the math
functions of the ccs!
I am using a PIC16F876A and the CCS Compiler IDE version 3.43 ; PCx
version 3.203
Thanks a lot in advance,
Thomas