Dim x为Decimal = 100.0m是否隐式执行从double到decimal的转换?

Xai*_*oft 4 vb.net

如果我有代码:

Dim x as Decimal = 100.0m
Run Code Online (Sandbox Code Playgroud)

是隐式地从双精度转换为十进制.我将如何在vb.net中明确地执行此操作?

Mat*_*att 6

我想你想要:

Dim x as Decimal = 100.0d
Run Code Online (Sandbox Code Playgroud)

C#中的十进制文字是m,但是d在vb.net中.这不会产生任何铸件.要将double转换为小数(r是vb.net中的双字面值),您可以说:

Dim x as Decimal = CType(100r, Decimal)
Dim x as Decimal = CType(100.0, Decimal)
Run Code Online (Sandbox Code Playgroud)