Display a "Non-integer"-Value with Berry in HASPmote #23575
-
Hello! How can i display a value (temperature) with decimal place. With this code it works that i display from a temperature only the integer part: def label_gh_temp_luft(topic, idx, payload_s, payload_b) I have tried to use "var" instead of "int". Thanks, Ralf |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
To convert to floating point use The best way to control decimal is to use
You can also use f-string syntax:
|
Beta Was this translation helpful? Give feedback.
-
Very good! |
Beta Was this translation helpful? Give feedback.
To convert to floating point use
real()
instead ofint()
The best way to control decimal is to use
format
global.p1b12.text=format("%.2f", real(payload_s))
(which would give you 2 decimals).You can also use f-string syntax:
global.p1b12.text=f"{real(payload_s):.2f}"