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

0 Members and 1 Guest are viewing this topic.

Offline miguelvp

  • Super Contributor
  • ***
  • Posts: 5550
  • Country: us
Re: Arduino and decimal numbers
« Reply #25 on: July 08, 2015, 06:42:05 pm »
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 08, 2015, 07:14:54 pm »
Yeah, there is no float support, this is why dtostrf()  exists.
Also, float are double on AVR.

Cheers.
---
Daniel
 

Offline alank2

  • Super Contributor
  • ***
  • Posts: 2185
Re: Arduino and decimal numbers
« Reply #27 on: July 09, 2015, 12: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