Quote:
Originally Posted by Tureyhall
%.3f means display a float with as many digits before the decimal as it needs, but limit it to three digits after the decimal.
%3.2f means display a float with three digits before the decimal, and two digits after the decimal.
|
These won't work in FRC code. The PIC18 chip used on the RC doesn't support floating point operations natively, so it's all done in software. Unfortunately, that software doesn't include the %f place holder. If you want to print a float, your only choice is to do something like this:
Code:
float variable = .... //Whatever float you're trying to print
int variabledeci; // Integer to hold the numbers after the decimal point
variabledeci = variable - (int)variable;
variabledeci*=1000;
printf("variable = %d.%03d", (int)variable, (int)variabledeci);
So, say that variable = 3.141
variabledeci = 3.141 - (int)3.141 = 3.141 - 3 = .141
variabledeci *= 1000 = 141
If you want more decimal places, make the 1000 into 10000, 100000, etc.