I tend to make things more complicated than they really are but would like someone to look at the following code and tell me if there would have been a better and easier way. The code works. Here's the problem:
If the decimal after a value is = or greater than .5 then I want to use "floor" with the next statement or "round" if it is less. The result will be the same number but that's what I want it to be.
Thanks,
Jim S.
If the decimal after a value is = or greater than .5 then I want to use "floor" with the next statement or "round" if it is less. The result will be the same number but that's what I want it to be.
B4X:
Dim part1,part2
Dim brgdms As String 'so main.bearingdms can be converted to string
If Main.dblBearingdms >= 0 Then
brgdms=Main.dblbearingdms 'convert to a string
brgdms=brgdms.Replace(".",",") ' replace the decimal in the number with a comma so it can be parsed
If brgdms.IndexOf (",")>0 Then 'verify the value has a decimal. Assume it has
parts=Regex.Split(",",brgdms) 'parse it
part1=parts(0) 'value in front of decimal
part2=parts(1) 'value behind decimal
End If
x= part2.IndexOf("5") 'find the index of the number 5 if present..it must be the first digit after the decimal to fit the requirement for flooring
If x=0 Then
deg=Floor(Main.dblbearingdms)
Else
deg=Round(Main.dblbearingdms)
End If
End If
Thanks,
Jim S.