decimal icon indicating copy to clipboard operation
decimal copied to clipboard

TrimTrailingZeros and AvoidScientificNotation bool variables

Open JohnAD opened this issue 1 year ago • 2 comments

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 avatar Dec 09 '24 00:12 JohnAD

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 avatar Dec 09 '24 02:12 JohnAD

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 avatar Dec 09 '24 04:12 JohnAD