public class MaximumPrecision extends Object implements Decimaliser
Decimaliser that converts floating-point numbers to decimal representation with a specified
maximum number of decimal places. During conversion, the number of decimal places will be limited to this maximum precision.
For example, if a maximum precision of 2 is specified, the number 1.238 will be converted to 1.24.
| Constructor and Description |
|---|
MaximumPrecision(int precision)
Creates a new MaximumPrecision object with the specified maximum precision.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
toDecimal(double value,
DecimalAppender decimalAppender)
Converts a double value to its decimal representation using the specified maximum precision, and appends it
to the provided
DecimalAppender. |
boolean |
toDecimal(float value,
DecimalAppender decimalAppender)
Converts a float value to its decimal representation using the specified maximum precision, and appends it
to the provided
DecimalAppender. |
public MaximumPrecision(int precision)
precision - the maximum number of decimal places to be used in the conversion.
Must be between 0 and 18, inclusive.IllegalArgumentException - if the precision is not between 0 and 18.public boolean toDecimal(double value,
DecimalAppender decimalAppender)
DecimalAppender.toDecimal in interface Decimaliservalue - the double value to be converted.decimalAppender - the DecimalAppender used to store and append the converted decimal value.AssertionError - if the conversion fails unexpectedly.public boolean toDecimal(float value,
DecimalAppender decimalAppender)
DecimalAppender.toDecimal in interface Decimaliservalue - the float value to be converted.decimalAppender - the DecimalAppender used to store and append the converted decimal value.AssertionError - if the conversion fails unexpectedly.Copyright © 2024. All rights reserved.