Java Utililty Methods Long Number Divide

List of utility methods to do Long Number Divide

Description

The list of methods to do Long Number Divide are organized into topic(s).

Method

longdiv(long dividend, long divisor)
div
if (dividend < 0) {
    return Math.round((double) (dividend - divisor + 1) / (double) divisor);
return Math.round((double) dividend / (double) divisor);
Stringdiv100(Long input)
div
if (input == null || input == 0) {
    return "0.0";
Double fl = input / 100d;
DecimalFormat df = new DecimalFormat("#.##");
df.setRoundingMode(RoundingMode.FLOOR);
return df.format(fl);
longdiv_ceil(long n, long d)
Div_ceil.
long v = (long) ((n / d) + (n % d != 0 ? 1 : 0));
return v;
longdivCeil(long a, long b)
div Ceil
if (b < 0) {
    return divCeil(-a, -b);
} else if (a >= 0) {
    return ((a + b - 1) / b);
return a / b;
doubledivide(final long dividend, final long divisor)
divide
if (divisor == 0)
    return 0;
return 1.0 * dividend / divisor;
Stringdivide(Long d1, Long d2)
divide
if (d1 == null || d2 == null || d2.equals(0l)) {
    return "0";
double percent = (double) d1 / d2;
DecimalFormat format = new DecimalFormat("0.00");
return format.format(percent);
longdivide(long dividend, long divisor)
Returns dividend / divisor, where the dividend and divisor are treated as unsigned 64-bit quantities.
if (divisor < 0) { 
    if (compareUnsigned(dividend, divisor) < 0) {
        return 0; 
    } else {
        return 1; 
if (dividend >= 0) {
...
doubledivide(long l1, long l2)
divide
NumberFormat nf = DecimalFormat.getInstance(Locale.ENGLISH);
DecimalFormat df = (DecimalFormat) nf;
df.applyPattern("#.##########");
double percent = (double) l1 / (double) l2;
return Double.parseDouble(df.format(percent));
longdivideAndRoundUp(long x, long y)
divide And Round Up
return (x + y - 1) / y;
longdivideForMean(long sum, long count)
Divides the sum by the count for an arithmetic mean.
return (count == 0) ? -1 : sum / count;