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

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

问题描述

如何将double 转换为decimal 用于货币开发.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;

请注意,浮点数不适合保持精确值,因此如果您先将数字相加,然后转换为 Decimal,则可能会出现舍入错误.您可能希望在将这些数字相加之前将它们转换为 Decimal,或者首先确保这些数字不是浮点数.

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天全站免登陆