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 and AvoidScientificNotation bool variables #389

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

JohnAD
Copy link

@JohnAD JohnAD commented Dec 9, 2024

This is a near-duplicate of #296 that preserves the @vasilbeckk 's work and commits. I will now start making the changes requested in #296.

@JohnAD JohnAD marked this pull request as draft December 9, 2024 00:57
@JohnAD
Copy link
Author

JohnAD commented Dec 9, 2024

I added the following tests for handling trailing zeros on negative precision. Such as "1000 to the nearest 100 should serialize as 1.0E2"

{"1.0000E3", "1000.0"}, // 1000 to the nearest tenth
{"1.000E3", "1000"},    // 1000 to the nearest one
{"1.0E3", "1.0E3"},     // 1000 to the nearest hundred
{"1E3", "1E3"},         // 1000 to the nearest thousand

(for those not familiar with scientific notation usage, it is required when precision is non-fractional. For example, the population of the U.S. is 314.9 million or, more properly 3.149E8. Any digit after the 9 is an unknown.)

This test does not pass the last two. I'll have to edit some code to fix the bug.

Given that zeros are not always trailing. Perhaps the TrimTrailingZeros option flag should be generically called IgnorePrecision or something like that?

@JohnAD
Copy link
Author

JohnAD commented Dec 9, 2024

Sadly, it appears that covering both cases breaks backwards compatibility. So, I've separated it out. I've added a AvoidScientificNotation option variable. It defaults to true and that default keeps the behavior the same.

As a bonus, I went ahead and made d.ScientificNotationString() a public function and added a unit test.

@JohnAD JohnAD marked this pull request as ready for review December 9, 2024 04:49
@JohnAD JohnAD changed the title WIP: String Trim Trailing Zeros bool variable String Trim Trailing Zeros bool variable Dec 9, 2024
@JohnAD JohnAD changed the title String Trim Trailing Zeros bool variable TrimTrailingZeros and AvoidScientificNotation bool variables Dec 10, 2024
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.

2 participants