Author Topic: Arduino and decimal numbers  (Read 7239 times)

0 Members and 1 Guest are viewing this topic.

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5549
  • Country: us
Re: Arduino and decimal numbers
« Reply #25 on: July 09, 2015, 04:42:05 am »
In that case, then use * for width and .* for precision so you can specify them on the fly

i.e.

sprintf(txt, "%*.*f", width, precision, val);

computing width and precision should be easy enough.

I think Arduino's printf doesn't support float formatting to save space by default, but there is a way to enable that functionality.

 

Offline f1rmb

  • Regular Contributor
  • *
  • Posts: 180
  • Country: fr
Re: Arduino and decimal numbers
« Reply #26 on: July 09, 2015, 05:14:54 am »
Yeah, there is no float support, this is why dtostrf()  exists.
Also, float are double on AVR.

Cheers.
---
Daniel
 

Offline alank2

  • Super Contributor
  • ***
  • Posts: 1919
Re: Arduino and decimal numbers
« Reply #27 on: July 09, 2015, 10:03:01 am »
I have a library for AVR gcc that is a printf that will allow you to specify the decimal places.  An integer of 123 with decimal places would be printed to a string as "1.23".

http://www.avrfreaks.net/projects/decimal-integer-sprintf-library
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf