public final class DoubleToDecimal extends Object
double as a string.| Modifier and Type | Field and Description |
|---|---|
int |
MAX_CHARS |
| Modifier and Type | Method and Description |
|---|---|
static Appendable |
appendTo(double v,
Appendable app)
Appends the rendering of the
v to app. |
static String |
toString(double v)
Returns a string rendering of the
double argument. |
public final int MAX_CHARS
public static String toString(double v)
double argument.
The characters of the result are all drawn from the ASCII set.
"NaN", regardless of the sign bit.
"Infinity" and "-Infinity", respectively.
"0.0" and "-0.0", respectively.
v is rendered as the sign
'-' followed by the rendering of the magnitude -v.
v is rendered in two stages:
v is selected
to represent v.
v is formatted as a string,
either in plain or in computerized scientific notation,
depending on its value.
A decimal is a number of the form d×10i for some (unique) integers d > 0 and i such that d is not a multiple of 10. These integers are the significand and the exponent, respectively, of the decimal. The length of the decimal is the (unique) integer n meeting 10n-1 ≤ d < 10n.
The decimal dv
for a finite positive v is defined as follows:
v
according to the usual round-to-closest rule of
IEEE 754 floating-point arithmetic.
v as
the decimal in T that is closest to v.
Or if there are two such decimals in T,
select the one with the even significand (there is exactly one).
The (uniquely) selected decimal dv
is then formatted.
Let d, i and n be the significand, exponent and
length of dv, respectively.
Further, let e = n + i - 1 and let
d1…dn
be the usual decimal expansion of the significand.
Note that d1 ≠ 0 ≠ dn.
v is formatted as
0.0…0d1…dn,
where there are exactly -(n + i) zeroes between
the decimal point and d1.
For example, 123 × 10-4 is formatted as
0.0123.
v is formatted as
d1…dn0…0.0,
where there are exactly i zeroes
between dn and the decimal point.
For example, 123 × 102 is formatted as
12300.0.
v is formatted as
d1…dn+i.dn+i+1…dn.
There are exactly -i digits to the right of
the decimal point.
For example, 123 × 10-1 is formatted as
12.3.
v.
Here e is formatted as by Integer.toString(int).
v is formatted as
d1.0Ee.
For example, 1 × 1023 is formatted as
1.0E23.
v is formatted as
d1.d2…dnEe.
For example, 123 × 10-21 is formatted as
1.23E-19.
v - the double to be rendered.public static Appendable appendTo(double v, Appendable app) throws IOException
v to app.
The outcome is the same as if v were first
rendered and the resulting string were then
appended to app.
v - the double whose rendering is appended.app - the Appendable to append to.IOException - If an I/O error occursCopyright © 2008–2022 FasterXML. All rights reserved.