Here you can find the source of format(final NumberFormat fmt, final double val)
Parameter | Description |
---|---|
fmt | formatter to use |
val | double value |
public static String format(final NumberFormat fmt, final double val)
//package com.java2s; import java.text.DateFormat; import java.text.FieldPosition; import java.text.NumberFormat; import java.util.Date; public class Main { /** formatter string buffer argument */ private final static StringBuffer _fmtBuffer = new StringBuffer(32); /** ignore formatter position argument */ private final static FieldPosition _ignorePosition = new FieldPosition(0); /**//ww w. ja v a 2s. co m * Format the given double value using given formater * * Note: this method is not thread safe (synchronization must be performed by callers) * * @param fmt formatter to use * @param val double value * @return formatted value */ public static String format(final NumberFormat fmt, final double val) { // reset shared buffer: _fmtBuffer.setLength(0); return format(fmt, _fmtBuffer, val).toString(); } /** * Format the given double value using given formater and append into the given string buffer * * Note: this method is thread safe * * @param fmt formatter to use * @param sb string buffer to append to * @param val double value * @return formatted value */ public static StringBuffer format(final NumberFormat fmt, final StringBuffer sb, final double val) { return fmt.format(val, sb, _ignorePosition); } /** * Format the given date using given formater * * Note: this method is not thread safe (synchronization must be performed by callers) * * @param fmt formatter to use * @param val date * @return formatted value */ public static String format(final DateFormat fmt, final Date val) { // reset shared buffer: _fmtBuffer.setLength(0); return format(fmt, _fmtBuffer, val).toString(); } /** * Format the given date using given formater and append into the given string buffer * * Note: this method is thread safe * * @param fmt formatter to use * @param sb string buffer to append to * @param val date * @return formatted value */ public static StringBuffer format(final DateFormat fmt, final StringBuffer sb, final Date val) { return fmt.format(val, sb, _ignorePosition); } }