From: Todd Heiks on
Why is 'ans1' true if double and false for single?

Module Module1
Sub Main()

Dim x As Double / Single
Dim y As Double / Single

Dim ans1 As Boolean
Dim ans2 As Boolean

x = 0.3000000000000001
y = Math.Round(x, 2)

ans1 = y = 0.3
ans2 = Math.Round(y, 2) = 0.3

End Sub
End Module

Thanks


From: GS on
Sub Main()
Dim x As Double, y As Double
Dim a As Single, b As Single
Dim ansX As Boolean, ansY As Boolean
Dim ansA As Boolean, ansB As Boolean

x = 0.3: y = Math.Round(x, 2)
a = 0.3: b = Math.Round(x, 2)

ansX = (y = 0.3)
ansY = (Math.Round(y, 2) = 0.3)
ansA = (y = 0.3)
ansB = (Math.Round(y, 2) = 0.3)
End Sub

This returns True for each Boolean (with OR without the math
expressions being wrapped in parenthesis).
--
Garry


From: MikeD on


"Todd Heiks" <Todd.Heiks_AT_NoSpam_GreatLakesWindow.com> wrote in message
news:OdvnfCq1KHA.752(a)TK2MSFTNGP04.phx.gbl...
> Why is 'ans1' true if double and false for single?
>
> Module Module1
> Sub Main()
>
> Dim x As Double / Single
> Dim y As Double / Single
>
> Dim ans1 As Boolean
> Dim ans2 As Boolean
>
> x = 0.3000000000000001
> y = Math.Round(x, 2)
>
> ans1 = y = 0.3
> ans2 = Math.Round(y, 2) = 0.3
>
> End Sub
> End Module


You need to ask this in one of the dotnet newsgroups. They all have
"dotnet" or "vsnet" in their name.

--
Mike


From: GS on
x = 0.300000000000001: y = Math.Round(x, 2)
a = 0.300000000000001: b = Math.Round(x, 2)

This also returns True for all Booleans. **Note there is one less zero
than your example because VB truncates what you posted to "0.3" as
shown in my previous post.
--
Garry


From: GS on
on 4/7/2010, MikeD supposed :
>
> "Todd Heiks" <Todd.Heiks_AT_NoSpam_GreatLakesWindow.com> wrote in message
> news:OdvnfCq1KHA.752(a)TK2MSFTNGP04.phx.gbl...
>> Why is 'ans1' true if double and false for single?
>>
>> Module Module1
>> Sub Main()
>>
>> Dim x As Double / Single
>> Dim y As Double / Single
>>
>> Dim ans1 As Boolean
>> Dim ans2 As Boolean
>>
>> x = 0.3000000000000001
>> y = Math.Round(x, 2)
>>
>> ans1 = y = 0.3
>> ans2 = Math.Round(y, 2) = 0.3
>>
>> End Sub
>> End Module
>
>
> You need to ask this in one of the dotnet newsgroups. They all have "dotnet"
> or "vsnet" in their name.

Well that explains why VB flagged the Dims in red! Do you mean that
they can actually declare multiple types in a single statement? (Shows
what I know about dotnet languages, huh!)
--
Garry