Java Fraction Format formatBet(Double betOdd, int formatterDigits)

Here you can find the source of formatBet(Double betOdd, int formatterDigits)

Description

Format bet.

License

Open Source License

Parameter

Parameter Description
betOdd the bet odd
formatterDigits the formatter digits

Return

the string

Declaration

public static String formatBet(Double betOdd, int formatterDigits) 

Method Source Code


//package com.java2s;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;

public class Main {
    /** The Constant DECIMAL_FORMAT_SYMBOLS. */
    private static final DecimalFormatSymbols DECIMAL_FORMAT_SYMBOLS = new DecimalFormatSymbols();
    /** The Constant DECIMAL_FORMATTER. */
    private static final DecimalFormat DECIMAL_FORMATTER = new DecimalFormat();

    /**//from  www .  ja v  a 2  s  .com
     * Format bet.
     * 
     * @param betOdd
     *            the bet odd
     * @param formatterDigits
     *            the formatter digits
     * @return the string
     */
    public static String formatBet(Double betOdd, int formatterDigits) {
        configureFormatter(formatterDigits);
        return DECIMAL_FORMATTER.format(betOdd);
    }

    /**
     * Format bet.
     * 
     * @param betOdd
     *            the bet odd
     * @param formatterDigits
     *            the formatter digits
     * @return the string
     */
    public static String formatBet(Float betOdd, int formatterDigits) {
        configureFormatter(formatterDigits);
        return DECIMAL_FORMATTER.format(betOdd);
    }

    /**
     * Formatter bet.
     * 
     * @param betOdd
     *            the bet odd
     * @param formatterDigits
     *            the formatter digits
     * @return the string
     */
    public static String formatBet(String betOdd, int formatterDigits) {
        configureFormatter(formatterDigits);
        return DECIMAL_FORMATTER.format(Double.valueOf(betOdd));
    }

    /**
     * Configure formatter.
     * 
     * @param digits
     *            the digits
     */
    private static void configureFormatter(int digits) {
        DECIMAL_FORMATTER.setRoundingMode(RoundingMode.HALF_UP);
        DECIMAL_FORMATTER.setMaximumFractionDigits(digits);
        DECIMAL_FORMATTER.setMinimumFractionDigits(digits);
        DECIMAL_FORMATTER.setGroupingUsed(false);

        DECIMAL_FORMAT_SYMBOLS.setDecimalSeparator('.');
        DECIMAL_FORMATTER.setDecimalFormatSymbols(DECIMAL_FORMAT_SYMBOLS);
    }
}

Related

  1. formatAmount(double number)
  2. formatAmount(final double mark)
  3. formatAnotherString(double valor)
  4. formataNum(double numero)
  5. formatAvgTime(double avg)
  6. formatBetHandicap(Double handicap)
  7. formatBytes(final double bytes)
  8. formatCoordinates(double lat, double lon)
  9. formatCPUUtilization(double d)