什么时候使用Decimal 类型(When to Use the Decimal Type)
来源:互联网 发布:什么是校园网络贷款 编辑:程序博客网 时间:2024/04/29 09:25
在货币或者财务方面的计算的时候建议使用decimal (System.Decimal)类型,或者在你需要使用很多位小数以及高精度的时候应该使用decimal 类型,以避免舍入方面的错误。
比如:
float f1 = 12345678901234567.28f; // 1.23456784E+16double d1 = 12345678901234567.28d; // 12345678901234568.0decimal dc1 = 12345678901234567.28m; // 12345678901234567.28
上面的例子中float和double类型都由于精度不,对所存储的数进行了舍弃。
decimal 类型提供更高的精度,但是它所能表示的数据范围却并不比 float 或者 double类型高,这是因为它将更多的位数用于存储小数位。
float – 4 bytes (±1.5e−45 to ±3.4e38, 7 位精度)
double – 8 bytes (±5.0e−324 to ±1.7e308, 位精度)
decimal – 16 bytes (±1.0 × 10−28 to ±7.9 × 1028, 28-29 位精度)
原文地址:https://csharp.2000things.com/2010/08/05/49-when-to-use-the-decimal-type/
********************************************译者注**************************************
decimal 类型是 128 位数据类型。同浮点型相比,decimal 类型具有更高的精度和更小的范围,这使它适合于财务和货币计算。如果希望实数被视为decimal 类型,请使用后缀 m 或 M。
decimal myMoney = 300.5m;如果,没有m。数字将会被视为double类型,从而导致编译错误。
0 0
- 什么时候使用Decimal 类型(When to Use the Decimal Type)
- 11.1.6 The decimal type
- decimal类型
- 使用Decimal类型格式化数据
- C#中,decimal类型使用
- Decimal
- Decimal
- Decimal
- Decimal
- decimal
- DECIMAL Data Type Characteristics
- DB2 DECIMAL data type
- MySQL decimal 类型
- MySQL decimal 类型
- mysql中的decimal类型
- DB2的DECIMAL类型
- MySQL decimal 类型
- 类型float与decimal
- 八大排序算法 简练讲解
- 使用ul实现下拉列表
- Android 开发指南(二) 服务绑定 Bound Service
- 【Android源码学习】View的layout和draw流程
- 第5章 引用类型(4)Array 类型
- 什么时候使用Decimal 类型(When to Use the Decimal Type)
- Android使用RecyclerViewHeader遇到的那些坑
- Android中的适配问题
- 检查文件格式
- 自定义全屏滑动返回手势
- Apache Rewrite实现URL的跳转和域名跳转
- Spark算子:统计RDD分区中的元素及数量
- Nginx静态资源性能测试
- 【软件项目管理】里程碑事件的定义