ossgang / ossgang-commons

Apache License 2.0
4 stars 0 forks source link

add "general" decimal format helper #72

Closed michi42 closed 1 year ago

michi42 commented 1 year ago

A variant of DecimalFormat that tries to be a bit smarter and mimics the format style "%g" (general, spec):

The double argument shall be converted in the style f or e (or in the style F or E in the case of a G conversion specifier), with the precision specifying the number of significant digits. If an explicit precision is zero, it shall be taken as 1. The style used depends on the value converted; style e (or E ) shall be used only if the exponent resulting from such a conversion is less than -4 or greater than or equal to the precision.

The threshold (both low and high) for switching to scientific format are configurable. There is a default constructor that tries to provide a compromise for "common" cases (exponential if >= 1e6 or <= 1e-4).

michi42 commented 1 year ago

Hi Michi, thanks for the new classes! Not sure if I understood everything correctly ... so as usual: Just consider my comments as ideas, not as 'have to change' ;-)

Thanks a lot for the review, very good points!

andreacalia commented 1 year ago

Looks good ! :+1: