public final class FloatToDecimal extends Object
float
as a string.Modifier and Type | Field and Description |
---|---|
int |
MAX_CHARS |
Modifier and Type | Method and Description |
---|---|
static Appendable |
appendTo(float v,
Appendable app)
Appends the rendering of the
v to app . |
static String |
toString(float v)
Returns a string rendering of the
float argument. |
public final int MAX_CHARS
public static String toString(float v)
float
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
.
A decimal is a number of the form d×10^{i} 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 10^{n-1} ≤ d < 10^{n}.
The decimal d_{v}
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
.
Or if there are two such decimals in T,
select the one with the even significand (there is exactly one).
The (uniquely) selected decimal d_{v} is then formatted.
Let d, i and n be the significand, exponent and length of d_{v}, respectively. Further, let e = n + i - 1 and let d_{1}…d_{n} be the usual decimal expansion of the significand. Note that d_{1} ≠ 0 ≠ d_{n}.
0.0
…0
d_{1}…d_{n},
where there are exactly -(n + i) zeroes between
the decimal point and d_{1}.
For example, 123 × 10^{-4} is formatted as
0.0123
.
0
…0.0
,
where there are exactly i zeroes
between d_{n} and the decimal point.
For example, 123 × 10^{2} is formatted as
12300.0
.
12.3
.
Integer.toString(int)
.
.0E
e.
For example, 1 × 10^{23} is formatted as
1.0E23
.
.
d_{2}…d_{n}E
e.
For example, 123 × 10^{-21} is formatted as
1.23E-19
.
v
- the float
to be rendered.public static Appendable appendTo(float 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 float
whose rendering is appended.app
- the Appendable
to append to.IOException
- If an I/O error occursCopyright © 2008–2022 FasterXML. All rights reserved.