I know, and I read reply #8 also.
It seems logical to you but it's very cryptic for someone like me who tries to understand but doesn't. So some extra information or maybe an example would help to better understand.
See also reply #18
Off the top of my head, a float should be able to represent numbers from about 10-38 to 10+38, but it can't possibly represent every value in that range
Example-1:
Figure-1 is an example that shows the storage pattern of the float number 0.15625 into memory as 32-bit value (0011 1100 0010 0000 0000 0000 0000 0000 in binary base; 3E200000 in hex base) in compliance with IEEE-754/binray32 standard.
Figure-1:
Example-2:
test code ...
unsigned long pulseCountInteger = 999999999;
word pulseCountFraction = 0;
void setup() {
Serial.begin(115200);
delay(1000);
}
void loop() {
pulseCountFraction += 1;
if (pulseCountFraction >= 1000) {
pulseCountFraction = 0;
pulseCountInteger += 1;
}
Serial.print("Pulse Count ");
Serial.print(pulseCountInteger);
if (pulseCountFraction < 10) Serial.print(".00");
else if (pulseCountFraction < 100) Serial.print(".0");
else Serial.print(".");
Serial.println(pulseCountFraction);
delay(10);
}
print output ...
Pulse Count 999999999.995
Pulse Count 999999999.996
Pulse Count 999999999.997
Pulse Count 999999999.998
Pulse Count 999999999.999
Pulse Count 1000000000.000
Pulse Count 1000000000.001
Pulse Count 1000000000.002
Pulse Count 1000000000.003
Pulse Count 1000000000.004
Pulse Count 1000000000.005
Pulse Count 1000000000.006
Pulse Count 1000000000.007
Pulse Count 1000000000.008
Pulse Count 1000000000.009
Pulse Count 1000000000.010
Pulse Count 1000000000.011
Pulse Count 1000000000.012
Yes. That's right.
Thanks all. It works now.
The solution is using an unsinged long for the value. multiply the factor times 10 and do the calculaton. After that devide the value by 10. I can now use a factor of 0.1 to 0.9 and whole numbers.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.





