Package me.croabeast.common
Class Rounder<T extends Number>
java.lang.Object
me.croabeast.common.Rounder<T>
- Type Parameters:
T- the type of the number, which must extendNumber
A utility class for rounding numbers to a specified number of decimal places.
The Rounder class supports various numeric types (e.g., Double, Integer, Float, etc.)
and provides methods to round a given number to a default of 2 decimal places or a custom amount.
Internally, it formats the number into a string using a customizable pattern and then parses it back
to the original numeric type.
-
Method Summary
-
Method Details
-
round
Rounds the given number to the default of 2 decimal places.- Type Parameters:
T- the type of the number- Parameters:
t- the number to be rounded- Returns:
- the rounded number with 2 decimal places
-
round
Rounds the given number to the specified number of decimal places.- Type Parameters:
T- the type of the number- Parameters:
decimalAmount- the desired number of decimal placest- the number to be rounded- Returns:
- the rounded number with the specified decimal places
-