public class NumberUtils
extends java.lang.Object
Constructor and Description |
---|
NumberUtils() |
Modifier and Type | Method and Description |
---|---|
static long |
getDaysAsMillis(int days)
Given an int value treat it as a number of days and return
the number of milliseconds for that number of days.
|
static java.lang.String |
getMillisAsFormattedSeconds(long millis)
Convert a number of milliseconds into seconds, we format to 2 decimal
places, i.e.
|
static double |
toPrecision(double v,
int digits)
Get the passed in double to the required precision.
|
public static double toPrecision(double v, int digits)
digits
set to 2, in which case: 11.78 will be returned. This method
is useful when you want to round a number after a multiple
decimal place division.
In essence it merely rounds the decimal part to the required number of digits using Math.round.
This method is most useful when provided in a suitable wrapper, for instance:
public float getAsCurrency (float v)
{
return (float) GeneralUtils.toPrecision (v, 2);
}
Note, it is safe to pass 0 as either of the parameters, it should be noted
that passing 0 as digits
has the same effect as calling: Math.round (v),
which makes sense since 0 digit precision of 11.77987 should be 12.
v
- The value to round.digits
- The number of decimal digits to round to.public static long getDaysAsMillis(int days)
days
- Number of days.public static java.lang.String getMillisAsFormattedSeconds(long millis)
millis
- The milliseconds to format.