Go Down

Topic: dtostrf() help (Read 138748 times) previous topic - next topic

PaulS

Quote
The LCD library I'm using won't print floats.

But, you don't want to print floats.
The art of getting good answers lies in asking good questions.

Nick_Pyner

#16
May 26, 2014, 04:16 am Last Edit: May 26, 2014, 04:39 am by Nick_Pyner Reason: 1

The LCD library I'm using won't print floats. I need to pass in a character array.


That is either nonsense, or time to move to a proper library. It is definitely time to be more forthcoming with your code.

If you want to print floats, you should be able to so - without dtostrf().
I have never been able to understand why there has ever been a need for this float to string conversion stuff, or why anybody thinks they need it now. I can only assume it is some nasty legacy from the past when Arduino was incapable of handling floats.

The only time I have ever seen a need for Arduino to feed strings was when a receiving non-Arduino programme demanded it  I'm not aware of any hardware device that demands to be fed with strings.

Another thread is here   http://forum.arduino.cc/index.php?topic=212255.msg1558900#msg1558900

mrthekod

I used dtostrf to pass an integer to a routine I wrote. It requires a char array that I then use chop each letter into vertical stripes to display on an LED cube.

Worked a treat for me. Kept me away from using String.

PaulS

Quote
I used dtostrf to pass an integer to a routine I wrote.
Why would you use double to string, formatted to deal with an integer?
The art of getting good answers lies in asking good questions.

mrthekod

Because it worked perfectly, I was planning on looking in to other more appropriate options later.

What would you use to tun an int into char array? I'm guessing there is itostrf, I didn't bother checking as this worked, and it was 4am, I was grumpy and I was calling this a win.

odometer

I used dtostrf to pass an integer to a routine I wrote.
Why? There are other ways, such as the sprintf function.
http://www.cplusplus.com/reference/cstdio/sprintf/
(Tip: Arduino won't let you use sprintf on floats, but integers are OK.)

odometer

#21
Jul 13, 2015, 12:52 pm Last Edit: Jul 13, 2015, 12:52 pm by odometer Reason: correct typo
What would you use to tun an int into char array? I'm guessing there is itostrf, I didn't bother checking as this worked, and it was 4am, I was grumpy and I was calling this a win.
I might, too, if it were 4 a.m. and I were grumpy.

But for myself, I use sprintf() or else arithmetic. And by arithmetic, I mean use division and modulus to get at the values of the digits, then add '0' (with single quotes) to each digit to convert it to a character.

chupo_cro

#22
Feb 08, 2017, 12:42 am Last Edit: Feb 08, 2017, 12:56 am by chupo_cro Reason: Corrected the link
I have never been able to understand why there has ever been a need for this float to string conversion stuff, or why anybody thinks they need it now. I can only assume it is some nasty legacy from the past when Arduino was incapable of handling floats.
Because sometimes you have to build the string so you can calculate the length to be able to make a POST request as mentioned in:

http://forum.arduino.cc/index.php?topic=85523.msg641844#msg641844
Chupo_cro

jimLee

Umm, you do realize your answering a question that was asked 2-3 years ago, right?

-jim lee
PNW Ardiuno & Maker club
1012 9Th Street, Anacortes, WA 98221 (Around the back of building)

chupo_cro

Quote from: jimLee Wed Feb 08 2017 04:21:34 GMT+0100 (Central European Standard Time)
Umm, you do realize your answering a question that was asked 2-3 years ago, right?

-jim lee
Yes I do. Is that a problem? I've found this thread when I was looking for some info about using floats with sprintf() and dtostrf() on avrlibc so there is a chance someone in the future will read this thread to find some useful infromation. I think the purpose of forum posts is (among the others) to be used as a knowledge base.

In fact, I created the account 2 years ago when I noticed a thread which was full of wrong informations (it was something related to millis() if I remember correctly) but then in the and I did not post anything.
Chupo_cro

Go Up