Calculate the order of magnitude of a number (float by now) - Java java.lang

Java examples for java.lang:Math Calculation

Description

Calculate the order of magnitude of a number (float by now)

Demo Code


//package com.java2s;

public class Main {
    /**/*w ww  . ja  va2 s .  co m*/
     * Calculate the order of magnitude of a number (float by now)
     *
     * @param range the input string
     * @return the resulting order
     */
    public static int getOrderOfMagnitude(int range) {

        int aux = range;
        int mag = 1;
        while (aux > 10) {
            mag = mag * 10;
            aux = aux / 10;
        }
        ;
        return mag;
    }
}

Related Tutorials