[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:

Code:
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.
Code:
lbResult.Text = NumberFormat(Rez, 0, 3) & " mV"
It works correctly, but the situation which I described above is unclear for me...
 

Attachments

Last edited:
If you look at the help Round2 returns a Double.
But you define a Float in the routine.
This works:
Code:
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.
 
Erel, Claus, thanks.
I understood this.
But why debugger shows value for Rez variable as 7.908 instead 7.907999456789?
It should be?
 
Back
Top