Loading...
Pages: [1]   Go Down
Author Topic: How can I limit the number of 54.00000000000  (Read 218 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 183
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

Netherlands
Offline Offline
Tesla Member
***
Karma: 90
Posts: 9407
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 -

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 315
Posts: 35519
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
Full Member
***
Karma: 0
Posts: 183
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello

Thank for your help
Cheers
Logged

UK
Offline Offline
Tesla Member
***
Karma: 89
Posts: 6391
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
myString.print(falt,DEC);

What type of object is 'myString'?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 183
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

UK
Offline Offline
Tesla Member
***
Karma: 89
Posts: 6391
-
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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 315
Posts: 35519
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
Tesla Member
***
Karma: 89
Posts: 6391
-
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

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 315
Posts: 35519
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
Print
 
Jump to: