PrString Question

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hello,

   

 

   

I have converted a float variable using ftoa and am writting to the LCD with " LCD_1_PrString(presult) "

   

I would like to limit the numer of places past the decimal point to two. Is ther an argument that I can add, I looked around but do not see how to do this.

   

 

   

Thanks,

   

 

   

Alan

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

ftoa() has no formatting capabilities, but you may use sprintf() for this. Have a look at this thread www.cypress.com/

   

Parameter explanation here : publications.gbdirect.co.uk/c_book/chapter9/formatted_io.html

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Ftoa() converts to an ascii string, so is the limitation in Prstring (ascii) has no modifiers?

   

I will look at  the link you provided but am still wondering if there is any way to truncate PrString out put to LCD.

   

 

   

Thanks,

   

Alan

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You may shorten the string yourself by placing an x00 at the appropiate place, but LCD_PrString() has no modifiers as the documentation of the API shows.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

sprintf() has a big impact on program space, should you decide to use

   

it attached formatting string information.

   

 

   

If you use Bob's suggestion search the string for the decimal point, then

   

search from there to where the NULL character is. If it is > 3 counts beyond

   

the DP point, place a NULL in the 3'rd position as Bob suggested. If it is

   

<= 3 counts do nothing to the string and print. A double nested for() loop

   

should do the job or something equivalent.

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

Thanks, For this project I decided to just use unsigned int Variables so I ended up using ITOA to print to LCD

   

 

   

Alan

0 Likes