Can't print floats??
Posted: Mon Jan 26, 2015 7:03 am
I am working on the Jaycar water flow gauge. I note the section
I print floats from my DS18B20 temperature sensor OK, so why can't I do that with the flow meter? Is this software out of date? Or is it actually quicker to go around the long way?
Code: Select all
// Because we want to output a // floating point value and print() can't handle floats we have to do some trickery // to output the whole number part, then a decimal point, then the fractional part. unsigned int frac; // Print the flow rate for this second in litres / minute Serial.print(int(flowRate)); // Print the integer part of the variable Serial.print("."); // Print the decimal point // Determine the fractional part. The 10 multiplier gives us 1 decimal place. frac = (flowRate - int(flowRate)) * 10; Serial.print(frac, DEC) ; // Print the fractional part of the variable