Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to support precision of 38 decimal #562

Closed
danhuiwang opened this issue Dec 29, 2022 · 3 comments
Closed

how to support precision of 38 decimal #562

danhuiwang opened this issue Dec 29, 2022 · 3 comments

Comments

@danhuiwang
Copy link

999995881114.744959800000000134 ,use decimal the result is 999995881114.7449598000000001

@schungx
Copy link
Contributor

schungx commented Dec 29, 2022

You only get 28 digits of precision for this type because it is based on 96 bits. You cannot get more precision than 28.

@paupino
Copy link
Owner

paupino commented Jan 13, 2023

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!

@Tony-Samuels
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants