Round down input value to nearest value of 10. - Java java.lang

Java examples for java.lang:Math Value

Description

Round down input value to nearest value of 10.

Demo Code


//package com.java2s;

public class Main {
    /**/*from www  .  j  a  va 2 s  . c  om*/
     * Round down input value to nearest value of 10. e.g. 323 returns 100. 
     * @param value
     * @return
     */
    public static int roundToNearestPowerOfTen(double value) {
        return (int) Math.pow(10, Math.floor(log10(value)));
    }

    /**
     * Calculates log base 10 of the specified value.
     */
    public static double log10(double value) {
        return Math.log(value) / Math.log(10);
    }
}

Related Tutorials