Here you can find the source of getFormat(double d)
Parameter | Description |
---|---|
d | _more_ |
public static DecimalFormat getFormat(double d)
//package com.java2s; /*/*from ww w. j a v a 2 s . c om*/ * Copyright (c) 2008-2018 Geode Systems LLC * * Licensed 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. */ import java.text.DecimalFormat; public class Main { /** _more_ */ private static DecimalFormat[] FORMATS = { new DecimalFormat("#0"), new DecimalFormat("#0.0"), new DecimalFormat("#0.00"), new DecimalFormat("#0.000"), new DecimalFormat("#0.0000"), new DecimalFormat("#0.00000"), }; /** * _more_ * * @param d _more_ * * @return _more_ */ public static DecimalFormat getFormat(double d) { d = Math.abs(d); if ((d > 10000) || (d == 0)) { return FORMATS[0]; } if (d > 1000) { return FORMATS[1]; } if (d > 100) { return FORMATS[2]; } if (d > 10) { return FORMATS[3]; } if (d > 1) { return FORMATS[4]; } return FORMATS[4]; } }