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

Changes to make Decimal serialization more deterministic with decimal places #1940

Conversation

barticus
Copy link

Summary of the changes (Less than 80 chars)

  • Change DecimalType serialization to use the "F" specifier rather than "E" which lost precision of decimal places once number had more than 6 significant digits
  • Also added an optional override for the decimal type to allow specifying of the number of decimal digits

Addresses #1929

@barticus
Copy link
Author

Hi @michaelstaib / @PascalSenn , this was a little more complex than i originally thought:

  1. The "F" specifier is more deterministic than "G", but by default only maintains 2 decimal places.
  2. As current behaviour would have allowed up to 6 decimal places, i've set the formatter, by default, to be "F6". This can be controlled by an overloaded constructor - let me know if theres a better way of exposing this
  3. To allow me to use the new variable for formatting, the method needed to become non-static.

So I think this will result in no breaking changes, but fix the issue as reported.

@michaelstaib
Copy link
Member

Not sure if we than should use F. I will have a look at this later.

@michaelstaib michaelstaib self-requested a review May 16, 2020 08:47
@michaelstaib michaelstaib linked an issue May 16, 2020 that may be closed by this pull request
@michaelstaib michaelstaib added this to the HC-10.5.0 milestone May 16, 2020
@barticus
Copy link
Author

Thanks Michael.
To me, F is a better fit than G. You can pull this branch and change the specifier to see the impacts it has.
But maybe to stop breaking changes, it is changed to G as the default, but if NumberDecimalDigits is specified, then use F.

@barticus
Copy link
Author

Hey @michaelstaib , anything further you want me to do on this one?

@michaelstaib
Copy link
Member

Sorry for the wait will look at this later

@bfink87
Copy link

bfink87 commented Jul 1, 2020

@michaelstaib Is this going to be merged into the 10.5 preview?

@michaelstaib
Copy link
Member

Yes, but I have to rework it first

@michaelstaib
Copy link
Member

But we will fix the issue

@bfink87
Copy link

bfink87 commented Jul 1, 2020

Thanks for the quick reply. Is there anything I can do to help? This bug is causing an issue in a project I'm working on.

@barticus
Copy link
Author

barticus commented Jul 1, 2020

Hi @bfink87,
You can copy this modified type into your project and use it instead of the inbuilt type if you need to work around the issue until the fix is available.

@michaelstaib it's disappointing you didnt ask for help seeing as I wrote this patch with guidance from yourself and Pascal, and even sought feedback with no response.

@michaelstaib
Copy link
Member

@barticus we are at the moment focused on version 11, but we will merge this one probably this week. We will change it to G as discussed with you.

michaelstaib
michaelstaib previously approved these changes Jul 2, 2020
@michaelstaib
Copy link
Member

@barticus I have removed NumberDecimalDigits since serialization/deserialization, in my opinion, should essentially lead to the same value. That was also my main hold up on this one. I will merge this one now and integrate it into preview-8. Sorry for the wait on this one but at the moment we are really focused on version 11 which really takes a lot of my attention right now. We try to get 10.5 out this week.

@michaelstaib
Copy link
Member

@barticus G does not contain only two digits; it will contain all significant digits.

@sonarcloud
Copy link

sonarcloud bot commented Jul 2, 2020

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 1 Code Smell

79.6% 79.6% Coverage
1.4% 1.4% Duplication

warning The version of Java (1.8.0_252) you have used to run this analysis is deprecated and we will stop accepting it from October 2020. Please update to at least Java 11.
Read more here

@michaelstaib michaelstaib merged commit 34c61a7 into ChilliCream:version_10_0_0_master Jul 2, 2020
@barticus
Copy link
Author

barticus commented Jul 2, 2020

Hi @michaelstaib,
Thanks for finishing this off.
Yes I had read the docs but I think was using G with a precision specifier and in that case it will revert to scientific notation if the significant digits is greater than the specified precision which wasn't a good thing to me.

Will v11 allow users to specify the precision they want on certain types?

@michaelstaib
Copy link
Member

@barticus not sure about this. What is the benefit of having zeros at the end?

@barticus
Copy link
Author

barticus commented Jul 2, 2020

@michaelstaib it's not about zeroes at the end, it's about matching the precision of your data types, especially DB types. If you only want to accept currency values up to 2 decimal places, it would be nice to be able to handle this at the type layer.
But if you have a suggestion/opinion on this, id be interested, I haven't been able to find what should be done for cases like this, e.g make a unique type for each precision, or handle it as a business logic check or some other middleware.
Thanks

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

Successfully merging this pull request may close these issues.

DecimalType loss of precision
3 participants