[Bug?] Float to Label.Text

Discorez

Member
Licensed User
Longtime User
I have a rounded float variable (in debugger I see it as 7.908), and I show
result in two labels, but I receive different results:

B4X:
Sub btCalc_Click
   Dim Rez As Float
   
   Rez = Round2(7.907999456789, 3) ' Rez debugger shows as "7.908"
   lbResult2.Text = Rez                    ' shows as "7.908"
        lbResult.Text = Rez & " mV"          ' shows as "7.907999456789 mV"
End Sub

:BangHead: Why?

test code is attached


Upd.
B4X:
lbResult.Text = NumberFormat(Rez, 0, 3) & " mV"
It works correctly, but the situation which I described above is unclear for me...
 

Attachments

  • Float2String.zip
    6.7 KB · Views: 267
Last edited:

klaus

Expert
Licensed User
Longtime User
If you look at the help Round2 returns a Double.
But you define a Float in the routine.
This works:
B4X:
Sub btCalc_Click
    Dim Rez As Double
    
    Rez = Round2(7.907999456789,3)
    lbResult.Text = Rez & " mV"
    lbResul2.Text = Rez
End Sub
But I agree it looks a bit strange.

Best regards.
 

Discorez

Member
Licensed User
Longtime User
Erel, Claus, thanks.
I understood this.
But why debugger shows value for Rez variable as 7.908 instead 7.907999456789?
It should be?
 
Top