Hello. First of all I want to say big thank for your hard work and good program. I am new in programming and ask you if you can add string.format and how to using them to textbox in WiKi. For example how to take Com1 freq and using for textbox.
Thank you so much.
P.S. Sorry for my English, my native language is Russian.
Help with String.format.
Re: Help with String.format.
Hi!
It just so happens that I figured that out yesterday. I wrote a small function that can be reused:
Use it like this:
You can learn a lot from existing instruments. I do it all the time.
It just so happens that I figured that out yesterday. I wrote a small function that can be reused:
Code: Select all
function frequency_to_string(frequency)
whole = math.floor(frequency) -- remove the decimal places
fract = var_round((frequency - whole)*100,2) -- get just the decimal places and round
return string.format("%d.%.02d",whole,fract) -- always show zeros (like 112.00)
end
Code: Select all
txt_set(my_textbox, frequency_to_string(COM1))
Re: Help with String.format.
Hello there...
I'm finishing up adjusting the clock I've coded some time ago to work on air manager v3.X.
On the timer, the minutes is derived by dividing secondds / 60. This may give a fraction of, let's say 35s will give me 0.5833. When I use the string format "%02.0f" it rounds up to 1, but in fact I still want to show 0. So when my timer goes beyond 30s the minutes become 1, which is not correct.
I've seen this bug in the "ATR 72-500 - Clock".
How can I format the number to just show me the number, excluding the decimals, and not round it up/down?
Thanks,
Filipe Bessa
I'm finishing up adjusting the clock I've coded some time ago to work on air manager v3.X.
On the timer, the minutes is derived by dividing secondds / 60. This may give a fraction of, let's say 35s will give me 0.5833. When I use the string format "%02.0f" it rounds up to 1, but in fact I still want to show 0. So when my timer goes beyond 30s the minutes become 1, which is not correct.
I've seen this bug in the "ATR 72-500 - Clock".
How can I format the number to just show me the number, excluding the decimals, and not round it up/down?
Thanks,
Filipe Bessa
Re: Help with String.format.
Hey,
Math.floor is your friend here I think, if I understand your question correctly
Corjan
Math.floor is your friend here I think, if I understand your question correctly
Code: Select all
val = 0.5833
print(string.format("%02.0f", math.floor(val)))
Corjan
Re: Help with String.format.
I definitely fix the problem! Thank you very much Corjan!
I'll submit this version of the Davtron clock.
Thanks,
Filipe
I'll submit this version of the Davtron clock.
Thanks,
Filipe