Can't print floats??

The EtherTen combines an Uno-equivalent Arduino-compatible board and Wiznet-based Ethernet support, along with a microSD card slot and Power-over-Ethernet support. [Product page]
Post Reply
ngp99
Posts: 49
Joined: Sat Jul 14, 2012 1:53 am
Location: Dee Why NSW

Can't print floats??

Post by ngp99 » Mon Jan 26, 2015 7:03 am

I am working on the Jaycar water flow gauge. I note the section

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
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?

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Can't print floats??

Post by andrew » Mon Jan 26, 2015 9:55 pm

That was published in early 2012, from my vague memory there was an issue with floats at the time so that was the simplest solution. It still works however you can of course change it if required.

ngp99
Posts: 49
Joined: Sat Jul 14, 2012 1:53 am
Location: Dee Why NSW

Re: Can't print floats??

Post by ngp99 » Tue Jan 27, 2015 5:29 am

Thank you. I found an old version I had from 2013, and realised that I had already changed it then to print floats and it works fine.

Post Reply