Here you can find the source of getFloatValue(double val, int len)
public static double getFloatValue(double val, int len)
//package com.java2s; public class Main { public static double getFloatValue(double val, int len) { if (len <= 0) { return val; }//w w w . ja va 2 s . co m int lastVal = (int) (val * (Math.pow(10, len + 1))) - ((int) (val * (Math.pow(10, len)))) * 10; if (lastVal < 5) { return ((int) (val * (Math.pow(10, len)))) / (Math.pow(10, len)); } else { return (((int) (val * (Math.pow(10, len)))) + 1) / (Math.pow(10, len)); } } }