Here you can find the source of truncate(double x, double gran)
public static double truncate(double x, double gran)
//package com.java2s; //License from project: Apache License public class Main { public static double truncate(double x, double gran) { return Math.round(x / gran) * gran; }/*from ww w.ja v a 2s . co m*/ public static int round(double number) { return (int) (Math.round(number) + 0.5); } public static int round(float number) { return (int) (Math.round(number) + 0.5); } }