I'm not a commons committer, but I think it moved to Java 8, where you
already have the same functionality available in the JDK. NumberFormat and
DecimalFormat [1] will do the same already, if I am not mistaken.

Ben

1: https://www.baeldung.com/java-number-formatting




On Thu, 13 May 2021, 17:59 Matt Juntunen, <matt.juntu...@hotmail.com> wrote:

> Hello,
>
> For the geometry IO work I did recently, I ended up creating a
> DoubleFormats [1] utility class that generates formatters for various
> floating point string representations. It creates formatters for plain
> (straight decimal), scientific, engineering, and mixed plain and scientific
> formats. A maximum number of significant decimal digits and a minimum
> exponent value can be specified for each format. Here is a simple example:
>
>
> int maxPrecision = 4;
>
> DoubleFormat plain = DoubleFormats.createPlain(maxPrecision);
> plain.format(Math.PI); // 3.142
> plain.format(-123456789); // -123500000.0
> plain.format(1.23456789e-6); // 0.000001235
>
> DoubleFormat eng = DoubleFormats.createEngineering(maxPrecision);
> eng.format(Math.PI); // 3.142
> eng.format(-123456789); // -123.5E6
> eng.format(1.23456789e-6); // 1.235E-6
>
>
> I currently have the methods returning a DoubleFormat functional interface
> but I plan on changing this to simply DoubleFunction<String>.
>
> Is there any interest in moving this functionality to commons-text? I find
> it quite useful since it is thread-safe and much faster than using
> String.format or similar. I've actually created a class with much the same
> functionality for use in my day job. It would be nice if I could use
> something from commons for that.
>
> Regards,
> Matt J
>
> [1]
> https://github.com/apache/commons-geometry/blob/master/commons-geometry-io-core/src/main/java/org/apache/commons/geometry/io/core/utils/DoubleFormats.java
>
>

Reply via email to