Java Fraction Format formatPrice(Double price)

Here you can find the source of formatPrice(Double price)

Description

Formats a Double representing a price into a string

License

Open Source License

Parameter

Parameter Description
price The price Double to be formatted

Return

A String with the formatted price

Declaration

public static String formatPrice(Double price) 

Method Source Code

//package com.java2s;
/*//from  w w w  .j a  v a2s .c  o  m
 * $Id: UtilFormatOut.java,v 1.1 2005/04/01 05:58:06 sfarquhar Exp $
 *
 *  Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a
 *  copy of this software and associated documentation files (the "Software"),
 *  to deal in the Software without restriction, including without limitation
 *  the rights to use, copy, modify, merge, publish, distribute, sublicense,
 *  and/or sell copies of the Software, and to permit persons to whom the
 *  Software is furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included
 *  in all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
 *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
 *  THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import java.text.DecimalFormat;

public class Main {
    static DecimalFormat priceDecimalFormat = new DecimalFormat("#,##0.00");

    /**
     * Formats a Double representing a price into a string
     *
     * @param price The price Double to be formatted
     * @return A String with the formatted price
     */
    public static String formatPrice(Double price) {
        if (price == null)
            return "";
        return formatPrice(price.doubleValue());
    }

    /**
     * Formats a double representing a price into a string
     *
     * @param price The price double to be formatted
     * @return A String with the formatted price
     */
    public static String formatPrice(double price) {
        return priceDecimalFormat.format(price);
    }
}

Related

  1. formatOneDecimal(double dNumber)
  2. formatOneDp(double inNumber)
  3. formatPair(double in, double out)
  4. formatPotencia(float potencia)
  5. formatPowerFloat(float averageRfTickSent)
  6. formatQuantity(Double quantity)
  7. formatRate(double events, double time, String event)
  8. formatSimpleDecimal(double d)
  9. formatSpeed(float speed)