Go Down

Topic: How can I limit the number of 54.00000000000 (Read 429 times) previous topic - next topic

pierrot10

Good afternoon,

I am looking to limit the number of decimal
this
Code: [Select]

myString.print(falt,DEC);


return 54.000000000
and I would like to have 54.00

Many thank
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

robtillaart

float f = 54.00000000;
Serial.print(f, 2);

If 54.00000 is a string your print statement wont work, ==> you need to convert the string to a float first ....
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

PaulS

Quote
I am looking to limit the number of decimal

You are telling it to print 10 decimal places. Why?

DEC is a #define with a value of 10.

pierrot10

Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

PeterH

I only provide help via the forum - please do not contact me for private consultancy.

pierrot10

Hello

myString is declared like this
Quote
PString myString(buffer,sizeof(buffer));


Did I answer to your question?

I solved my probleme like @robtillaart suggeseted

Serial.print(value, 2)
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!

PeterH


Hello

myString is declared like this
Quote
PString myString(buffer,sizeof(buffer));


Did I answer to your question?


Yes. Your answer tells us that to understand your original problem, it is necessary to look at the interface to the PString class. That's where you should have looked, to understand why the call to print() wasn't doing what you expected. (The online documentation I found at http://arduiniana.org/libraries/PString didn't have any detail about the API, but presumably it's documented somewhere.)
I only provide help via the forum - please do not contact me for private consultancy.

PaulS

Quote
The online documentation I found at http://arduiniana.org/libraries/PString didn't have any detail about the API

If you download the library, though, you see that PString derives from Print, so the other threads are correct.

PeterH


If you download the library, though, you see that PString derives from Print, so the other threads are correct.


The API documentation is the code? Sadly, that's not as unusual as it should be.
I only provide help via the forum - please do not contact me for private consultancy.

PaulS

Quote
The API documentation is the code?

It is for me. It's never wrong. It's never three versions behind.

Go Up