Java Number Round roundToWord(long value)

Here you can find the source of roundToWord(long value)

Description

Return the smallest multiple of four (4) that is greater than or equal to the given value.

License

Open Source License

Parameter

Parameter Description
value the value to be rounded up to the nearest multiple of four

Return

the smallest multiple of four that is greater than or equal to the value

Declaration

private static long roundToWord(long value) 

Method Source Code

//package com.java2s;
/*/*from   w  w w . j a  v a 2s  . c o  m*/
 * Copyright (c) 2013, the Dart project authors.
 * 
 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */

public class Main {
    /**
     * An array containing the amount by which a value must be incremented in order to round it up to
     * the nearest multiple of four when the index into the array is the remainder after dividing the
     * value by four.
     */
    private static final long[] ROUND_UP_AMOUNT = { 0L, 3L, 2L, 1L };

    /**
     * Return the smallest multiple of four (4) that is greater than or equal to the given value.
     * 
     * @param value the value to be rounded up to the nearest multiple of four
     * @return the smallest multiple of four that is greater than or equal to the value
     */
    private static long roundToWord(long value) {
        return value + ROUND_UP_AMOUNT[(int) (value % 4)];
    }
}

Related

  1. roundToSignificantDigits(double x, double y, int nSignif)
  2. roundToSignificantFigures(double num, int n)
  3. RoundToStr(double value, int dec)
  4. roundToString(double nb2round, int nbOfDigits)
  5. roundToTop(float f)
  6. roundToZero(float x)
  7. roundTwoDecimals(double value)
  8. roundUp(double a)
  9. roundUp(double d)