将双变量强制转换为十进制 [英] Cast a Double Variable to Decimal

查看:99
本文介绍了将双变量强制转换为十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个人如何将转换为十进制,这在进行货币开发时会使用。 M 去哪里了?

How does one cast a double to decimal which is used when doing currency development. Where does the M go?

decimal dtot = (decimal)(doubleTotal);


推荐答案

您只能使用 M 表示数字文字,当您强制转换时只是:

You only use the M for a numeric literal, when you cast it's just:

decimal dtot = (decimal)doubleTotal;

请注意,浮点数不适合保留确切的值,因此,如果您先加数字一起转换为十进制,可能会出现舍入错误。您可能需要先将数字转换为十进制,然后再将它们转换为整数,或者确保数字不是浮点数。

Note that a floating point number is not suited to keep an exact value, so if you first add numbers together and then convert to Decimal you may get rounding errors. You may want to convert the numbers to Decimal before adding them together, or make sure that the numbers aren't floating point numbers in the first place.

这篇关于将双变量强制转换为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆