Here you can find the source of truncateDoubleDecimals(double x1, int num)
public static double truncateDoubleDecimals(double x1, int num)
//package com.java2s; /*// www . j av a 2 s. co m * Copyright (C) 2007 Alberto Duina, SPEDALI CIVILI DI BRESCIA, Brescia ITALY * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ public class Main { public static double truncateDoubleDecimals(double x1, int num) { double mult1 = Math.pow(10, num); int mult = (int) mult1; double y1; double y2; if (x1 > 0) { y1 = Math.floor(x1 * mult); y2 = y1 / (mult); } else { y1 = Math.ceil(x1 * mult); y2 = y1 / (mult); } return y2; } }