Java Fraction Format formatBetHandicap(Double handicap)

Here you can find the source of formatBetHandicap(Double handicap)

Description

Format bet handicap.

License

Open Source License

Parameter

Parameter Description
handicap the handicap

Return

the string

Declaration

public static String formatBetHandicap(Double handicap) 

Method Source Code


//package com.java2s;

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 HANDICAP_FORMATTER. */
    private static final DecimalFormat HANDICAP_FORMATTER = new DecimalFormat();

    /**//from  w  w  w  .  j a v a2 s.co  m
     * Format bet handicap.
     *
     * @param handicap the handicap
     * @return the string
     */
    public static String formatBetHandicap(Double handicap) {
        configureFormatterHandicap();
        String result;
        String handicapStr = HANDICAP_FORMATTER.format(handicap);
        if (handicap > 0) {
            result = new StringBuffer("+").append(handicapStr).toString();
        } else if (handicap < 0) {
            result = handicapStr;
        } else {
            result = "0";
        }
        return result;
    }

    /**
     * Configure formatter handicap.
     */
    private static void configureFormatterHandicap() {
        HANDICAP_FORMATTER.setGroupingUsed(false);
        HANDICAP_FORMATTER.setMaximumFractionDigits(2);

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

Related

  1. formatAmount(final double mark)
  2. formatAnotherString(double valor)
  3. formataNum(double numero)
  4. formatAvgTime(double avg)
  5. formatBet(Double betOdd, int formatterDigits)
  6. formatBytes(final double bytes)
  7. formatCoordinates(double lat, double lon)
  8. formatCPUUtilization(double d)
  9. formatD(double d)