Pages: [1]   Go Down
Author Topic: How can I limit the number of 54.00000000000  (Read 407 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Good afternoon,

I am looking to limit the number of decimal
this
Code:
myString.print(falt,DEC);

return 54.000000000
and I would like to have 54.00

Many thank
Logged

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

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 217
Posts: 13705
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ....
Logged

Rob Tillaart

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49339
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello

Thank for your help
Cheers
Logged

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

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
myString.print(falt,DEC);

What type of object is 'myString'?
Logged

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

Offline Offline
Sr. Member
****
Karma: 0
Posts: 399
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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)
Logged

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

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.)
Logged

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49339
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

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

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 613
Posts: 49339
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The API documentation is the code?
It is for me. It's never wrong. It's never three versions behind.
Logged

Pages: [1]   Go Up
Jump to: