Here you can find the source of round(double number, int places)
Parameter | Description |
---|---|
number | the number which should be rounded. |
places | the number of places which should be kept. |
public static double round(double number, int places)
//package com.java2s; /*//from ww w . j a va 2s . c o m * Copyright (C) Keanu Poeschko - All Rights Reserved * Unauthorized copying of this file is strictly prohibited * * Created by Keanu Poeschko <nur1popcorn@gmail.com>, April 2017 * This file is part of {Irrlicht}. * * Do not copy or distribute files of {Irrlicht} without permission of {Keanu Poeschko} * * Permission to use, copy, modify, and distribute my software for * educational, and research purposes, without a signed licensing agreement * and for free, is hereby granted, provided that the above copyright notice * and this paragraph appear in all copies, modifications, and distributions. * * * * */ public class Main { /** * @param number the number which should be rounded. * @param places the number of places which should be kept. * * @return the provided number rounded to the number of places. */ public static double round(double number, int places) { assert places > 0; final double multiplier = Math.pow(10, places); return (int) (number * multiplier) / multiplier; } }