I am able to display pressure data from a BMP180 sensor in whole numbers but would like it to display to one decimal point.

This is the code I am using.

mylcd.lcd_display_string(“Pressure: %d%s hPa” % (pressure,chr(32)), 4)

Unfortunately researching the internet only gives me suggestions for displaying to the screen and not the LCD.

Thanks in advance for any help.

  • that cannot possibly be all of the code ... we have no way to guess what program you are using
    – jsotola
    Dec 8, 2019 at 2:09
  • Hi @Larry C, Ah let me see. Suppose you already know that have a floating point number with two decimal places, eg, 12.34. But now the raw data is decimal integer. 1234. So you divide floating point raw data by 100 to get first two digits. If you understand my trick, then of course you know how to get the decimal digits. Then I convert the first int to string S1, similarly S2. Then the string to disaplay is S3 = S1 + ',' + S2.
    – tlfong01
    Dec 8, 2019 at 8:37
  • Using python is easy, because there are many useful string functions like checking length, cutting head and tails, left and right justify etc. Another trick is use hex(raw binary number representing the floating pint number) to get the number as a string, and do the fiddling. Yes, it is tedious, the friendly manual is hard to understand. But I usually do trails and errors.
    – tlfong01
    Dec 8, 2019 at 8:39
  • How to move the "cursor" or first char position is also a bit tricky. But once you crawl over the block, then everything is a piece of cake! :) The 16 x 2 or 20 x 4 LCD algorithm is very "similar". The manual is not clear, usually written by a Japanese guy in Japanese style wrong English grammar. But once you get used to the strange Japanese syntax, you can read their incorrect grammar manuals many time faster than the native English speakers. :)
    – tlfong01
    Dec 8, 2019 at 8:45

1 Answer 1


If I understand correctly, this is not a Pi problem, but a C programming issue.

In C printf (and variants), %d means 'Output an integer' - which is what you are getting.

You need %f to output a float, or a double. If you only want one decimal point, use %.1f:

mylcd.lcd_display_string(“Pressure: %.1f%s hPa” % (pressure,chr(32)), 4)

There is lots of help online, e.g. https://www.cprogramming.com/tutorial/printf-format-strings.html

  • Works perfectly Peter bill. Also appreciate the link. I have bookmarked it.
    – Larry C
    Dec 9, 2019 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.