Number format

joeyschlatter

New Member
Licensed User
I have a Listbox that is displaying the GPS altitude but i would like to limit the number of decimal places to 2. i was looking through help topics but it was not very clear to me, being a new user.

current code:
Sub GPS_GPSDecoded
ListBox1.Clear
ListBox1.add(GPS.status)
ListBox2.Clear
ListBox2.Add(GPS.NumberOfSatellites)
ListBox3.Clear
ListBox3.add(GPS.SpeedOverGround)
ListBox4.Clear
ListBox4.Add(GPS.CourseOverGround)
ListBox5.Clear
ListBox5.Add(GPS.Altitude * 3.28084)
End Sub

Any help would be great,

(just got this software this morning and so far i love it)
 

Erel

Administrator
Staff member
Licensed User
You should use the Format keyword:
B4X:
ListBox5.Add(Format(GPS.Altitude * 3.28084,"n2"))
GPS.Altitude is parsed from the GPS string.
You should check if it is not an empty string (there is no altitude value):
B4X:
If GPS.Altitude <> "" Then
  ListBox5.Add(Format(GPS.Altitude * 3.28084,"n2"))
End If
BTW, why don't you use a TextBox or a Label instead of the ListBoxes?
 
Top