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

precision, scale #99

Closed
samstride opened this issue Dec 28, 2020 · 6 comments
Closed

precision, scale #99

samstride opened this issue Dec 28, 2020 · 6 comments

Comments

@samstride
Copy link

samstride commented Dec 28, 2020

Firstly, thank you for making this library available.

We use CRDB as our data store and this library when we need to do decimal operations.

Following taken from CRDB docs:

DECIMAL(precision, scale), where precision is the maximum count of digits both to the left and right of the decimal point 
and scale is the exact count of digits to the right of the decimal point.
.
.
.
When inserting a decimal value:

If digits to the right of the decimal point exceed the column's scale, CockroachDB rounds to the scale.
If digits to the right of the decimal point are fewer than the column's scale, CockroachDB pads to the scale with 0s.

What is the best way to achieve CRDB's precision, scale with apd v2? An example would be handy.

What is the best way to round digits to the right of the decimal point with apd v2 ? An example would be handy.

@samstride
Copy link
Author

@mjibson , are you able to help with this issue?

@maddyblue
Copy link
Contributor

https://github.com/cockroachdb/cockroach/blob/8187c2551352a6c28eba021effaebcbfe523d78c/pkg/sql/sem/tree/decimal.go#L58 is how cockroach does this.

@samstride
Copy link
Author

@mjibson , thanks will have a look.

@samstride
Copy link
Author

@mjibson , I put this together - https://play.golang.org/p/Skm023JrE3U

Seems to be working. Let me know if I got something wrong?

Also, I feel it would be useful to have that LimitDecimalWidth feature in apd v2 itself. What are your thoughts on this? I am happy to submit a PR if I can get some guidance.

Once again, thanks for helping out.

@maddyblue
Copy link
Contributor

maddyblue commented Mar 18, 2021

apd is well-scoped to be whatever http://speleotrove.com/decimal/ provides and tries really hard to not do more things. That function is possibly useful as a documented example instead of an included function. However I no longer have merge permission to this repo so am unable to help out too much making that happen beyond reviewing a PR.

@samstride
Copy link
Author

@mjibson , Thanks. I guess if someone ever uses apd v2 and wants to achieve precision,scale, the information in this conversation should help them.

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

2 participants