0

formatting variable to display on 4 x 20 lcd
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

formatting variable to display on 4 x 20 lcd

by frankups1 on Wed Apr 07, 2021 11:36 am

Hello, I am trying to display a temperature value stored in a mysql database onto a 4x20 character lcd. i am using adafruit lcd char_lcd library. i am able to display the temperature value but i can't figure out how to remove the 'decimal' from the display.

Code: Select all | TOGGLE FULL SIZE
    lcd.message(F'Temp: {r}')


"r" is the temperature value

this is the code i am using and it works but unfortunately it displays as:
IMG_1306.jpeg
IMG_1306.jpeg (281.98 KiB) Viewed 26 times


Thanks in advance!

frankups1
 
Posts: 1
Joined: Wed Apr 07, 2021 10:55 am

Re: formatting variable to display on 4 x 20 lcd

by dastels on Wed Apr 07, 2021 11:55 am

You could use:
Code: Select all | TOGGLE FULL SIZE
"Temp: {0:.2f}".format(f)


Dave

dastels
 
Posts: 5884
Joined: Tue Oct 20, 2015 3:22 pm

Re: formatting variable to display on 4 x 20 lcd

by tannewt on Wed Apr 07, 2021 11:56 am

Try `{r:d}`. This adds a digit format specifier. See here for details: https://docs.python.org/3/tutorial/inpu ... g-literals

tannewt
 
Posts: 2349
Joined: Thu Oct 06, 2016 8:48 pm

Please be positive and constructive with your questions and comments.