简体   繁体   English

Dart/Flutter 中 Money 的数据类型

[英]Data Type for Money in Dart/Flutter

It is common knowledge that typical floating point data types (aka float and double ) are in Base 2, thus are bad for storing money because Base 2 numbers can not always accurately represent Base 10 numbers like money.众所周知,典型的浮点数据类型(又名floatdouble )在 Base 2 中,因此不利于存储货币,因为 Base 2 数字不能总是像货币一样准确地表示 Base 10 数字。 To avoid this issue, languages such as Java have implemented data types such as BigDecimal.为了避免这个问题,Java 等语言实现了 BigDecimal 等数据类型。 Is there any similar data type for Dart/Flutter? Dart/Flutter 有类似的数据类型吗?

As Abion47 said, the best way to store money would be to use the decimal package , which is like BigDecimal in Java and has a load of useful features.正如 Abion47 所说,最好的存钱方式是使用十进制 package ,它就像 Java 中的 BigDecimal 一样,具有很多有用的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM