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

trimTrailingZeros should be an option #31

Closed
jayd3e opened this issue Oct 15, 2016 · 4 comments
Closed

trimTrailingZeros should be an option #31

jayd3e opened this issue Oct 15, 2016 · 4 comments

Comments

@jayd3e
Copy link

jayd3e commented Oct 15, 2016

Right now it's assumed that trailing zeros should be removed upon a call to Value, as a decimal is being serialized into the database. This doesn't take into account cases where you want to keep the number of decimal places consistent across the board. For example, if I created a Decimal via:

dec, _ := decimal.NewFromString("100.00")

I would expect it to enter the database as "100.00". When in actuality, the trailing zeros are removed and "100" is saved. This creates some interesting scenarios when storing and retrieving decimals from the database. I would expect the precedent to be that decimals are represented as a string in exactly the same way they were created, unless the user does an operation that would change the precision(such as using StringFixed).

@ocZio
Copy link

ocZio commented Dec 2, 2016

@jayd3e what about using the StringFixed instead?

edit:
Sorry, just saw your last paragraph where you mention StringFixed. The outcome should be the same for the database, 100.00 === 100

Is it just for aesthetics or you genuinely have a use case where it does make sense to keep the zeros?

@jayd3e
Copy link
Author

jayd3e commented Feb 28, 2018

I just ran into this issue again today due to this commit. Yeah, I really don't think it's the job of the library to make these kinds of decisions on precision. If I enter "100.00" into a decimal type, I expect to get "100.00" back out again. It's deceiving to have the precision changed by the library. This is especially true when you are putting the value into the database and retrieving it again. You want the decimal value to be exactly the same as what you entered into the database, but under the current system, it is being changed. Thanks in advance for the thought that is put into this.

@mwoss
Copy link
Member

mwoss commented Dec 9, 2019

Hi @jayd3e. This will be fixed in the next releases. Stay tuned.
Parent issue: #107

@mwoss
Copy link
Member

mwoss commented Feb 27, 2020

Fixed in #159 (revert of #46). Closing.

@mwoss mwoss closed this as completed Feb 27, 2020
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

3 participants