将双变量转换为十进制

编程入门 行业动态 更新时间:2024-10-28 04:25:45
本文介绍了将双变量转换为十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将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屋!

更多推荐

[db:关键词]

本文发布于:2023-03-28 12:44:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/728130.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   变量   十进制

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!