Java Double Number Round round(double number, int places)

Here you can find the source of round(double number, int places)

Description

round

License

Open Source License

Parameter

Parameter Description
number the number which should be rounded.
places the number of places which should be kept.

Return

the provided number rounded to the number of places.

Declaration

public static double round(double number, int places) 

Method Source Code

//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;
    }
}

Related

  1. round(double number)
  2. round(double number, double multiplier)
  3. round(double number, int decimal)
  4. round(double number, int digit)
  5. round(double number, int digits)
  6. round(double number, int places)
  7. round(double number, int precision)
  8. round(Double number, Integer precision)
  9. round(Double ret, Integer doublePrecision)