Java Number Format Pattern format(final long l)

Here you can find the source of format(final long l)

Description

Formats a number.

License

Open Source License

Parameter

Parameter Description
l a number.

Return

a string containing a pretty print of the number.

Declaration

public static String format(final long l) 

Method Source Code

//package com.java2s;
/*       //from   ww  w  . j a  v a2  s.c  o  m
 * DSI utilities
 *
 * Copyright (C) 2002-2009 Sebastiano Vigna 
 *
 *  This library 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 2.1 of the License, or (at your option)
 *  any later version.
 *
 *  This library 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 this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 */

public class Main {
    /** A reasonable format for real numbers. */
    private static final java.text.NumberFormat FORMAT_DOUBLE = new java.text.DecimalFormat("#,##0.00");
    /** A reasonable format for integers. */
    private static final java.text.NumberFormat FORMAT_LONG = new java.text.DecimalFormat("#,###");

    /** Formats a number.
     *
     * <P>This method formats a double separating thousands and printing just two fractional digits.
     * @param d a number.
     * @return a string containing a pretty print of the number.
     */
    public static String format(final double d) {
        final StringBuffer s = new StringBuffer();
        return FORMAT_DOUBLE.format(d, s, new java.text.FieldPosition(0)).toString();
    }

    /** Formats a number.
     *
     * <P>This method formats a long separating thousands.
     * @param l a number.
     * @return a string containing a pretty print of the number.
     */
    public static String format(final long l) {
        final StringBuffer s = new StringBuffer();
        return FORMAT_LONG.format(l, s, new java.text.FieldPosition(0)).toString();
    }
}

Related

  1. createNumberFormat()
  2. createNumberFormat(int cnt)
  3. createOrderVolumeNumberFormat()
  4. createRealFormat()
  5. expFormatRupiah(Number input, boolean prependRp)
  6. format(final long value, final long divider, final String unit)
  7. format(Integer num)
  8. format(long bytes)
  9. format(long value)