I need to insert decimal point into string which is converted from word variable.
String will be transmitted via serial port to terminal software for monitoring.
For this project I'm using old mikroBasic v7.0.0.2 (not PRO version).
I have writen this code and it is working as expected, but do you have more "elegant" solution for this problem?
Code: Select all
sub procedure WordToStrWithDecimalPoint(dim wInput as word, dim byref sOut as string[6])
dim sTemp as string[5]
sOut = ""
WordToStr(wInput, sTemp)
if (wInput >= 0) and (wInput < 10) then
sOut[0] = " "
sOut[1] = " "
sOut[2] = "0"
sOut[3] = "."
sOut[4] = "0"
sOut[5] = sTemp[4]
end if
if (wInput >= 10) and (wInput < 100) then
sOut[0] = " "
sOut[1] = " "
sOut[2] = "0"
sOut[3] = "."
sOut[4] = sTemp[3]
sOut[5] = sTemp[4]
end if
if (wInput >= 100) and (wInput < 1000) then
sOut[0] = " "
sOut[1] = " "
sOut[2] = sTemp[2]
sOut[3] = "."
sOut[4] = sTemp[3]
sOut[5] = sTemp[4]
end if
if (wInput >= 1000) and (wInput < 10000) then
sOut[0] = " "
sOut[1] = sTemp[1]
sOut[2] = sTemp[2]
sOut[3] = "."
sOut[4] = sTemp[3]
sOut[5] = sTemp[4]
end if
if (wInput >= 10000) and (wInput <= $FFFF) then
sOut[0] = sTemp[0]
sOut[1] = sTemp[1]
sOut[2] = sTemp[2]
sOut[3] = "."
sOut[4] = sTemp[3]
sOut[5] = sTemp[4]
end if
sOut[6] = 0
end sub