Here you can find the source of round(final double val, final int decimalPlaces)
Parameter | Description |
---|---|
val | The coordinate value. |
decimalPlaces | The number of decimal place to round to. |
public static double round(final double val, final int decimalPlaces)
//package com.java2s; /**// w w w .j a va2s .com * Licensed to the TomTom International B.V. under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. TomTom International B.V. * licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ public class Main { /** The default precision for rounding coordinate values. */ private static final int DEFAULT_PRECISION = 5; /** Integer of value 10. */ private static final int TEN = 10; /** * Round. * * @param val * the val * @return the double */ public static double round(final double val) { return round(val, DEFAULT_PRECISION); } /** * Rounds a coordinate value (longitude or latitude) to a specific * precision. * * @param val * The coordinate value. * @param decimalPlaces * The number of decimal place to round to. * @return The rounded value. */ public static double round(final double val, final int decimalPlaces) { return Math.round(val * Math.pow(TEN, decimalPlaces)) / Math.pow(TEN, decimalPlaces); } }