Hello,
I am trying to achieve the following functionality to display my TCAS range:
txt_set(txt_range, 74/milestopixels)
The problem is, that if the result is a whole number, the resulting text contains a decimal zero.
Current functionality:
result = 10 -> shown text = 10.0
result 2.5 -> shown text = 2.5
Required functionality:
result = 10 -> shown text = 10 (without decimal zero)
result 2.5 -> shown text = 2.5
Anybody has an easy solution please?
Thank you!
Pavel
How to remove decimal zero
How to remove decimal zero
Pavel Brodský
Prague, Czech Republic
Prague, Czech Republic
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: How to remove decimal zero
Hi,
Are you talking about format?
_txt(tostring(string.format("%03.0f",10)--- will give "010"
_txt(tostring(string.format("%.0f",10)--- will give " 10" no leading zeros
_txt(tostring(string.format("%.1f",10)--- will give " 10.0" no leading zeros one trailing decimal
var_round(10.1,0) will give "10"
var_round(10.0,1) will give "10.0"
Keith
Are you talking about format?
_txt(tostring(string.format("%03.0f",10)--- will give "010"
_txt(tostring(string.format("%.0f",10)--- will give " 10" no leading zeros
_txt(tostring(string.format("%.1f",10)--- will give " 10.0" no leading zeros one trailing decimal
var_round(10.1,0) will give "10"
var_round(10.0,1) will give "10.0"
Keith
Last edited by Keith Baxter on Thu Apr 22, 2021 12:44 pm, edited 1 time in total.
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
Re: How to remove decimal zero
Hello and thank you,
I know those, but I believe they always remove the decimal, even if I want it to be displayed.
I need 2.5 to remain 2.5, but I also need 2.0 to be 2.
Pavel
I know those, but I believe they always remove the decimal, even if I want it to be displayed.
I need 2.5 to remain 2.5, but I also need 2.0 to be 2.
Pavel
Pavel Brodský
Prague, Czech Republic
Prague, Czech Republic
- Keith Baxter
- Posts: 4685
- Joined: Wed Dec 20, 2017 11:00 am
- Location: Botswana
Re: How to remove decimal zero
Hi,
Ahhh
Have you tried string match?
Keith
Ahhh
Have you tried string match?
Keith
AMD RYZEN 9 5950X CPU, Corsair H80I cooler, ASUS TUF GAMING B550-PLUS AMD Ryzen Mother Board, 32Gb ram Corsair Vengeance 3000Mh, MSI GTX960 4G graphics card
Re: How to remove decimal zero
If I think a bit longer there is likely something better, perhaps using Regex maybe but what about this for a top of the head idea.
var = fif(var % 1 == 0, math.floor(var), var)
var = fif(var % 1 == 0, math.floor(var), var)
Air Manager panels at https://www.experimentalsimavionics.com
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Youtube Channel https://www.youtube.com/channel/UC8ZqXX ... kfZMq5BKig
Air Manager API Tutorial Video Series https://youtube.com/playlist?list=PLNr0 ... baT4gJKg5D
Re: How to remove decimal zero
Sling, this works so good! Thank you.
Pavel
Pavel
Pavel Brodský
Prague, Czech Republic
Prague, Czech Republic