Here you can find the source of formatBet(Double betOdd, int formatterDigits)
Parameter | Description |
---|---|
betOdd | the bet odd |
formatterDigits | the formatter digits |
public static String formatBet(Double betOdd, int formatterDigits)
//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); } }