Can somebody please give me a hand with this:
I am new to Lua and need to convert a Longitude (GPS) Double to a specific string representation.
I am trying to convert my Pascal routines to lua.
I got this far:
function DegreesToLongStr(LongD) – Where LongD is a double and result is a string
local AChar = “”
local D = 0
local M = 0
local Dstr = “”
local MStr = “”
if LongD < 0 – Its negative
then
AChar = “W”
LongD = -LongD – make it positive
else
AChar = “E”
end
d = trunc(LongD) – I cannot find this in Lua. if LongD = 123.456789 then d = 123 and m = .456789
m = frac(LongD)*60
Dstr = IntToStr(d) – convert integer d to string Dstr
while string.len(Dstr) < 3 do DStr = “0”…DStr end – hope this works. Needs leading zeros.
Mstr = FloatToStrF(m,ffFixed,4,2) – convert double m to formatted string
while string.len(MStr) < 5 do MStr = “0”…Mstr end
return = Dstr…Mstr…Achar
end
result should be: “12327.40W” …I think.
Any help appreciated…