Java Double Number mod modulo10(double d, boolean round)

Here you can find the source of modulo10(double d, boolean round)

Description

Returns the integer result of (d mod 10).

License

Apache License

Parameter

Parameter Description
d a double to mod against 10
round if <b>true</b> the double will be rounded to the nearest long, if <b>false</b> floor() will be called.

Return

an integer between 0 and 9 of the mod result

Declaration

public static int modulo10(double d, boolean round) 

Method Source Code

//package com.java2s;
/*//w  w w.  j  a va2 s.c o m
Copyright 1996-2008 Ariba, Inc.
    
Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
    
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.
    
$Id: //ariba/platform/util/core/ariba/util/core/MathUtil.java#11 $
*/

public class Main {
    /**
    Returns the integer result of (d mod 10).  If round is true, then
    result will be rounded, otherwise, the resulted will be the greatest
    integer at or below the result.
        
    @param d a double to mod against 10
    @param round if <b>true</b> the double will be rounded to the
    nearest long, if <b>false</b> floor() will be called.
        
    @return an integer between 0 and 9 of the mod result
    @aribaapi documented
    */
    public static int modulo10(double d, boolean round) {
        long l = round ? Math.round(d) : (long) Math.floor(d);
        int i = (int) (l % 10);
        return i;
    }
}

Related

  1. modifiedGramSchmidt(double[][] s)
  2. modifiedJulianToJulian(double modifiedJulian)
  3. modifySize(double[] x, int newLen)
  4. modPI2(double angle)
  5. Modulo(double x, double y)
  6. moduloAngle(double angle)
  7. moduloTwoPI(double x)
  8. modValue(double v, int precision)