Go Down

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

#### pierrot10

##### Jan 12, 2013, 06:07 pm
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!
You can not know everything, perseverance, it is almost everything!

#### robtillaart

#1
##### Jan 12, 2013, 06:13 pm
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

#2
##### Jan 12, 2013, 06:15 pm
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

#3
##### Jan 12, 2013, 07:16 pm
Hello

Thank for your help
Cheers
Il ne suffit pas de tout savoir, la persévérance, c'est déjà presque tout!
You can not know everything, perseverance, it is almost everything!

#### PeterH

#4
##### Jan 13, 2013, 03:51 am

Code: [Select]
`myString.print(falt,DEC);`

What type of object is 'myString'?
I only provide help via the forum - please do not contact me for private consultancy.

#### pierrot10

#5
##### Jan 13, 2013, 12:10 pm
Hello

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

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!
You can not know everything, perseverance, it is almost everything!

#### PeterH

#6
##### Jan 13, 2013, 05:36 pm

Hello

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

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

#7
##### Jan 13, 2013, 06:08 pm
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

#8
##### Jan 13, 2013, 08:01 pm

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

#9
##### Jan 13, 2013, 08:04 pm
Quote
The API documentation is the code?

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

Go Up

Please enter a valid email to subscribe