Java Fraction Format formatDoube(double val)

Here you can find the source of formatDoube(double val)

Description

This method is used to format the value to 2 decimal places if val is 800.0 then this method will return 800.00 if val is 800.136 then this method will return 800.14

License

Open Source License

Parameter

Parameter Description
val a parameter

Declaration

public static String formatDoube(double val) 

Method Source Code

//package com.java2s;
/*/* ww  w  . j  a  v  a2s .  c  om*/
 * @(#)ConversionUtil.java
 *
 * Copyright by ObjectFrontier, Inc.,
 * 12225 Broadleaf Lane, Alpharetta, GA 30005, U.S.A.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information
 * of ObjectFrontier, Inc. You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of
 * the license agreement you entered into with ObjectFrontier.
 */

import java.text.DecimalFormat;

public class Main {
    protected static DecimalFormat doubleStringFormat = new DecimalFormat("0.00");

    /**
     * This method is used to format the value to 2 decimal places
     * if val is 800.0 then this method will return 800.00
     * if val is 800.136 then this method will return 800.14
     * @param val
     * @return
     */
    public static String formatDoube(double val) {
        return doubleStringFormat.format(String.valueOf(val));
    }
}

Related

  1. formatDecNumber(Double number, String pattern)
  2. formatDegToDms(double degrees, double min, double max)
  3. formatDisplay(Double value)
  4. formatDistance(float distance)
  5. formatDollarAmount(float amount)
  6. formatDouble(DecimalFormat fmt, double value)
  7. formatDouble(Double amount, String format)
  8. formatDouble(double aValue)
  9. formatDouble(double d)