how to support precision of 38 decimal
danhuiwang opened this issue · 3 comments
999995881114.744959800000000134 ,use decimal the result is 999995881114.7449598000000001
You only get 28 digits of precision for this type because it is based on 96 bits. You cannot get more precision than 28.
Hi @danhuiwang,
As @schungx points out - this library only supports 28 digits of precision at present. When parsing a string it tries to round the value (safely) to fit into the provided format - which in this case drops the last two digits of precision. If you want to avoid this implicit rounding you can instead use from_str_exact
which will instead error if it can't parse the entire decimal.
A maximum scale of 28 is a hard limit of this library at present - it is something I'd like to investigate with version 2 of this library using const generics however this requires a few more nightly features to be stabilized first.
If you need a library with a larger precision then I believe you can utilize bigdecimal
. This uses a BigInteger
behind the scenes which can grow in size accordingly.
Let me know if you have any further questions!
A maximum scale of 28 is a hard limit of this library at present - it is something I'd like to investigate with version 2 of this library using const generics however this requires a few more nightly features to be stabilized first.
If this comes out, it is likely to be as a new crate, at least initially. Closing this out for now.