Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Dim x as Decimal = 100.0m do a cast from double to decimal implicitly?

Tags:

vb.net

If I have the code:

Dim x as Decimal = 100.0m

Is it casting from a double to a decimal implicitly. How would I do this explicitly in vb.net?

like image 397
Xaisoft Avatar asked Jan 20 '23 03:01

Xaisoft


1 Answers

I think you want:

Dim x as Decimal = 100.0d

The decimal literal in C# is m, but is d in vb.net. This produces no casting whatsoever. To cast a double to a decimal (r is the double literal in vb.net) you could say:

Dim x as Decimal = CType(100r, Decimal)
Dim x as Decimal = CType(100.0, Decimal)
like image 52
Matt Avatar answered May 10 '23 17:05

Matt