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

F

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
 
C

Chris Dunaway

Franky said:
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
 
F

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
 
F

Franky

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

55 - d.value

thanks
 
C

Chris Dunaway

Franky said:
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
 
F

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top