List of utility methods to do Number Round
float | roundPower10(float val, int powerOf10) Round a float to a particular power of 10 double precision = Math.pow(10, powerOf10); double mantisa = Math.floor((val / precision) + 0.5); float value = (float) (mantisa * precision); return value; |
long | roundPower2(final long x) Finds greater nearest number that is power of 2 int rval = 256; while (rval < x) rval <<= 1; return rval; |
double | roundRadian(double rad) Round radian value in range -pi/2 to pi/2 final double pi2 = Math.PI * 2; if (rad > 0) { return rad - pi2 * (int) ((rad + Math.PI) / pi2); } else { return rad + pi2 * (int) ((-rad + Math.PI) / pi2); |
int | roundRobin(final int value) round Robin int roundRobin = 0; for (int i = 1; i < value; i++) { roundRobin += i; return roundRobin; |
double | roundScale(double value, int scale) round Scale double d = Math.pow(10, scale); return Math.round(value * d) / d; |
Double | roundScale2(Number number) rounds the number to a value with 2 decimal digits {Category} NumberUtil {talendTypes} double | Double {param} double(2.5) number: number to format {example} numberToString(1234.12345) result: 1234.12 if (number != null) { return Math.round(number.doubleValue() * 100d) / 100d; } else { return null; |
int | roundSec(int sec) round Sec for (int i = 0; i * STEP < 60; i++) { if (sec >= i && sec < STEP * (i + 1)) { sec = i * STEP; break; return sec; |
long | roundSec(long milli) round Sec return ((milli + 500L) / 1000L) * 1000L;
|
double | roundSig(double d, int n) round Sig if (d != d) { return Double.NaN; if (d == 0) { return 0; int power = n - (int) Math.ceil(Math.log10(d < 0 ? -d : d)); double magnitude = Math.pow(10, power); ... |
double | roundSignificant(double d, int numDigit, boolean keepInteger) Round specified value to specified number of significant digit. If keepInteger is true then integer part of number is entirely conserved. final double digit = Math.ceil(Math.log10(Math.abs(d))); if ((digit >= numDigit) && keepInteger) return Math.round(d); final double pow = Math.pow(10, numDigit - digit); return Math.round(d * pow) / pow; |