在 C# 中用于金钱的最佳数据类型是什么? [英] What is the best data type to use for money in C#?

查看:25
本文介绍了在 C# 中用于金钱的最佳数据类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C# 中用于货币的最佳数据类型是什么?

What is the best data type to use for money in C#?

推荐答案

正如 十进制 为:

decimal 关键字表示 128 位数据类型.相比浮点类型,十进制类型具有更高的精度和较小的范围,这使得它适合金融和货币计算.

The decimal keyword indicates a 128-bit data type. Compared to floating-point types, the decimal type has more precision and a smaller range, which makes it appropriate for financial and monetary calculations.

您可以按如下方式使用小数:

You can use a decimal as follows:

decimal myMoney = 300.5m;

这篇关于在 C# 中用于金钱的最佳数据类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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