/double2string

Convert Double/Float to String

Primary LanguageJavaOtherNOASSERTION

Double2String Build StatuscodecovMaven CentraljavadocApache License, Version 2.0

This Java library only contains a single class Double2String that contains two utility functions: getDoubleString(double value) and getFloatString(float value).

These two functions essentially return the equivalent of "%g" output of C printf for 64-bit and 32-bit floating point values. The resulting strings are compact representations of the floating values.

The necessity of this library is because Java's printf and NumberFormat do not have equivalent functionalities. For instance, the output of System.out.printf ("%g", 1.1) is 1.10000. The compact representation should be 1.1.

Maven

	<dependency>
		<groupId>org.yuanheng</groupId>
		<artifactId>double2string</artifactId>
		<version>1.0.0</version>
	</dependency>

Algorithm

The algorithm and code used here are from Jaffer, Aubrey. "Easy Accurate Reading and Writing of Floating-Point Numbers." arXiv preprint arXiv:1310.8121 (2013). PDF.

License

Please see LICENSE.txt. It contains the license from Aubrey Jaffer for his code, and the Apache License for the extensions.