Home All Groups Group Topic Archive Search About

Can a Decimal variable be set to "Not a Number"

Author
20 Nov 2006 1:41 PM
Franky
Can a Decimal variable be set to "Not a Number"

I've been looking in the help and can't find any reference to that.


Thanks in advance

Author
20 Nov 2006 1:52 PM
Chris Dunaway
Franky wrote:
> Can a Decimal variable be set to "Not a Number"
>

I don't think so, but you can declare a variable of Nullable(Of
Decimal) and set it Nothing:

Dim d As Nullable(Of Decimal)

d = Nothing


Then in code you can check if it is assigned a value:

If d.HasValue Then
    'Do Something
End If

This only works with .Net 2.0
Author
20 Nov 2006 2:11 PM
Franky
Thanks. If I understand the Help I if x is Decimal I can use d as if it is
Decimal

Dim d As Nullable(Of Decimal)

....

If d.HasValue Then
    x=d
End If


Thanks again


Show quoteHide quote
"Chris Dunaway" <dunaw***@gmail.com> wrote in message
news:1164030723.516423.25260@b28g2000cwb.googlegroups.com...
> Franky wrote:
>> Can a Decimal variable be set to "Not a Number"
>>
>
> I don't think so, but you can declare a variable of Nullable(Of
> Decimal) and set it Nothing:
>
> Dim d As Nullable(Of Decimal)
>
> d = Nothing
>
>
> Then in code you can check if it is assigned a value:
>
> If d.HasValue Then
>    'Do Something
> End If
>
> This only works with .Net 2.0
>
Author
20 Nov 2006 2:17 PM
Franky
No in general I guess I can't use like it is a double. Need to use:

55 - d.value

thanks

Show quoteHide quote
" Franky" <frankyNOSPAM@a-znet.com> wrote in message
news:uoC0Q3KDHHA.2176@TK2MSFTNGP04.phx.gbl...
> Thanks. If I understand the Help I if x is Decimal I can use d as if it is
> Decimal
>
> Dim d As Nullable(Of Decimal)
>
> ...
>
> If d.HasValue Then
>    x=d
> End If
>
>
> Thanks again
>
>
> "Chris Dunaway" <dunaw***@gmail.com> wrote in message
> news:1164030723.516423.25260@b28g2000cwb.googlegroups.com...
>> Franky wrote:
>>> Can a Decimal variable be set to "Not a Number"
>>>
>>
>> I don't think so, but you can declare a variable of Nullable(Of
>> Decimal) and set it Nothing:
>>
>> Dim d As Nullable(Of Decimal)
>>
>> d = Nothing
>>
>>
>> Then in code you can check if it is assigned a value:
>>
>> If d.HasValue Then
>>    'Do Something
>> End If
>>
>> This only works with .Net 2.0
>>
>
>
Author
20 Nov 2006 4:22 PM
Chris Dunaway
Franky wrote:
> No in general I guess I can't use like it is a double. Need to use:
>

That's because it is a Decimal and not a double.  If you need a double,
then use double instead of decimal:

        Dim d As Nullable(Of Double)

        d = 14.56

        Dim d2 As Double

        If d.HasValue Then
            d2 = d.Value * 3
        Else
            d2 = 0.0
        End If

Chris
Author
20 Nov 2006 4:49 PM
Franky
I meant to say Decimal not Double.

I meant, I can't simply add to d, I must add to d.value

It's too bad they didn't take the max value and use that as NaN and decrease
the max available by 1.

I could get by with the max a little smaller


=====================I meant to say

No in general I guess I can't use like it is a decimal. Need to use:

55 - d.value

rather than

55-d

==================================

But I see you set  d = 14.56 not  d.Value = 14.56

How come you can do that?

thanks again


Show quoteHide quote
"Chris Dunaway" <dunaw***@gmail.com> wrote in message
news:1164039730.716843.151240@j44g2000cwa.googlegroups.com...
> Franky wrote:
>> No in general I guess I can't use like it is a double. Need to use:
>>
>
> That's because it is a Decimal and not a double.  If you need a double,
> then use double instead of decimal:
>
>        Dim d As Nullable(Of Double)
>
>        d = 14.56
>
>        Dim d2 As Double
>
>        If d.HasValue Then
>            d2 = d.Value * 3
>        Else
>            d2 = 0.0
>        End If
>
> Chris
>