Java Double Number Format FormatDouble(double p_value, int p_numberOfDecimalPlaces)

Here you can find the source of FormatDouble(double p_value, int p_numberOfDecimalPlaces)

Description

Format Double

License

Open Source License

Declaration

static public String FormatDouble(double p_value, int p_numberOfDecimalPlaces) 

Method Source Code

//package com.java2s;
/*/*from ww w  .  ja va2 s .c  o m*/
   Copyright 2016 Wes Kaylor
    
   This file is part of CoreUtil.
    
   CoreUtil is free software: you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
    
   CoreUtil 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 Lesser General Public License for more details.
    
   You should have received a copy of the GNU Lesser General Public License
   along with CoreUtil.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    static public String FormatDouble(double p_value, int p_numberOfDecimalPlaces) {
        String t_valueString = Double.toString(p_value);
        if (t_valueString.contains(".")) {
            int t_decimalIndex = t_valueString.indexOf(".");
            if ((t_valueString.length() - (t_decimalIndex + 1)) > p_numberOfDecimalPlaces) {
                t_valueString = t_valueString.substring(0, (t_decimalIndex + (p_numberOfDecimalPlaces + 1)));
            }
        }
        return t_valueString;
    }
}

Related

  1. formatDouble(double d, int n)
  2. formatDouble(double d, int n, String pad)
  3. formatDouble(double d, int precision)
  4. formatDouble(double inDouble, boolean inComma, int inCommaPos)
  5. formatDouble(double num, int width, int precision)
  6. formatDouble(double source, int decimals, int precision)
  7. formatDouble(double v, int decimalPlaces)
  8. formatDouble(double val)
  9. formatDouble(double val)