How to remove decimal zero

Help creating logic scripts for Air Manager Instruments

Moderators: Ralph, russ

Post Reply
Message
Author
User avatar
brodhaq
Posts: 144
Joined: Wed Jun 29, 2016 4:13 pm

How to remove decimal zero

#1 Post by brodhaq » Thu Apr 22, 2021 12:32 pm

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
Pavel Brodský
Prague, Czech Republic

User avatar
Keith Baxter
Posts: 2806
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: How to remove decimal zero

#2 Post by Keith Baxter » Thu Apr 22, 2021 12:43 pm

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
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 

User avatar
brodhaq
Posts: 144
Joined: Wed Jun 29, 2016 4:13 pm

Re: How to remove decimal zero

#3 Post by brodhaq » Thu Apr 22, 2021 12:44 pm

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
Pavel Brodský
Prague, Czech Republic

User avatar
Keith Baxter
Posts: 2806
Joined: Wed Dec 20, 2017 11:00 am
Location: Botswana

Re: How to remove decimal zero

#4 Post by Keith Baxter » Thu Apr 22, 2021 12:49 pm

Hi,

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 

User avatar
Sling
Posts: 4431
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: How to remove decimal zero

#5 Post by Sling » Thu Apr 22, 2021 1:30 pm

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)

User avatar
brodhaq
Posts: 144
Joined: Wed Jun 29, 2016 4:13 pm

Re: How to remove decimal zero

#6 Post by brodhaq » Wed May 05, 2021 1:09 pm

Sling, this works so good! Thank you.

Pavel
Pavel Brodský
Prague, Czech Republic

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests