Here you can find the source of formatBetHandicap(Double handicap)
Parameter | Description |
---|---|
handicap | the handicap |
public static String formatBetHandicap(Double handicap)
//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); } }