public class UsesBigDecimal extends Object implements Decimaliser
Decimaliser
that uses BigDecimal
for higher-precision conversions of floating-point
numbers to decimal representation.
This implementation is designed for scenarios where precision is of utmost importance, and is suitable for handling very large numbers or numbers with a large number of decimal places.
Note: Using BigDecimal
might incur a performance overhead compared to more lightweight approaches.
Modifier and Type | Field and Description |
---|---|
static Decimaliser |
USES_BIG_DECIMAL
A singleton instance of
UsesBigDecimal for convenient reuse. |
Constructor and Description |
---|
UsesBigDecimal() |
Modifier and Type | Method and Description |
---|---|
boolean |
toDecimal(double value,
DecimalAppender decimalAppender)
Converts a double value to its decimal representation using
BigDecimal and appends it
to the provided DecimalAppender . |
boolean |
toDecimal(float value,
DecimalAppender decimalAppender)
Converts a float value to its decimal representation using
BigDecimal and appends it
to the provided DecimalAppender . |
public static final Decimaliser USES_BIG_DECIMAL
UsesBigDecimal
for convenient reuse.
This instance is thread-safe and can be used across multiple threads without synchronization.public boolean toDecimal(double value, DecimalAppender decimalAppender)
BigDecimal
and appends it
to the provided DecimalAppender
.
If the input is not a finite number or is a negative zero, the conversion will not be performed.
toDecimal
in interface Decimaliser
value
- The double value to be converted.decimalAppender
- The DecimalAppender
used to store and append the converted decimal value.true
if the conversion and appending were successful, false
otherwise.public boolean toDecimal(float value, DecimalAppender decimalAppender)
BigDecimal
and appends it
to the provided DecimalAppender
.
If the input is not a finite number, the conversion will not be performed.
toDecimal
in interface Decimaliser
value
- The float value to be converted.decimalAppender
- The DecimalAppender
used to store and append the converted decimal value.true
if the conversion and appending were successful, false
otherwise.Copyright © 2024. All rights reserved.