Android Question NO rounding, just truncating.

bodycode

Member
Licensed User
Longtime User
I'd like to do the following.

Dim myDouble as double = 2100.947987

I would then like to assign the value to a label, but truncated, and not rounded. The label would display

2011.947, but not 2011.95?

Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code shows the full number:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   Dim lbl As Label
   Dim d As Double = 2100.947987
   Log(d)
   lbl.Initialize("")
   Activity.AddView(lbl, 0, 0, 300dip, 100dip)
   lbl.Text = d
End Sub

It is usually better to use NumberFormat to covert a number to string:
B4X:
lbl.Text = NumberFormat2(d, 0, 10, 0, False)
 
Upvote 0

bodycode

Member
Licensed User
Longtime User
Ok then. Got it. Thank you.

This code shows the full number:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   'Activity.LoadLayout("Layout1")
   Dim lbl As Label
   Dim d As Double = 2100.947987
   Log(d)
   lbl.Initialize("")
   Activity.AddView(lbl, 0, 0, 300dip, 100dip)
   lbl.Text = d
End Sub

It is usually better to use NumberFormat to covert a number to string:
B4X:
lbl.Text = NumberFormat2(d, 0, 10, 0, False)
 
Upvote 0
Top