Android Question NumberFormat2 not working quite as I expect

barx

Well-Known Member
Licensed User
Longtime User
I'm wanting to show a number in an Edittext as x.xx with 2 decimal point values shown all the time
e.g 1.00, 0.96, 0.90, etc

With the following code I get:
1.0, 0.99, 0.98, 0.97, 0.96, 0.95, 0.94, 0.93, 0.92, 0.91, 0.9, .......


B4X:
    Sub btnShadeDown_Click
       If txtShade.Text > 0 Then
         Dim NewShade As Double = NumberFormat2((txtShade.Text - 0.01), 0, 2, 2, False)
         Log(NewShade)
         txtShade.Text = NewShade
       End If
     End Sub

How comes 2 decimal places are not show each time?

Thanks
 

DonManfred

Expert
Licensed User
Longtime User
B4X:
Sub btnShadeDown_Click
       If txtShade.Text > 0 Then
         Dim NewShade As Double =  (txtShade.Text - 0.01)
         Log(NumberFormat2(NewShade, 0, 2, 2, False))
         txtShade.Text = NumberFormat2(NewShade, 0, 2, 2, False)
       End If
     End Sub
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
B4X:
Sub btnShadeDown_Click
       If txtShade.Text > 0 Then
         Dim NewShade As Double =  (txtShade.Text - 0.01)
         Log(NumberFormat2(NewShade, 0, 2, 2, False))
         txtShade.Text = NumberFormat2(NewShade, 0, 2, 2, False)
       End If
     End Sub
Ah yes, silly me.

My Head is mushy peas this morning. Not thinking straight at all. Thanks @DonManfred
 
Upvote 0
Top