當前位置: 首頁>>代碼示例>>Java>>正文


Java DecimalFormatSymbols.getInstance方法代碼示例

本文整理匯總了Java中java.text.DecimalFormatSymbols.getInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java DecimalFormatSymbols.getInstance方法的具體用法?Java DecimalFormatSymbols.getInstance怎麽用?Java DecimalFormatSymbols.getInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.DecimalFormatSymbols的用法示例。


在下文中一共展示了DecimalFormatSymbols.getInstance方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getInstance

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
private NumberFormat getInstance(Locale locale,
                                        int choice) {
    if (locale == null) {
        throw new NullPointerException();
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    String[] numberPatterns = adapter.getLocaleResources(locale).getNumberPatterns();
    DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
    int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
    DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);

    if (choice == INTEGERSTYLE) {
        format.setMaximumFractionDigits(0);
        format.setDecimalSeparatorAlwaysShown(false);
        format.setParseIntegerOnly(true);
    } else if (choice == CURRENCYSTYLE) {
        adjustForCurrencyDefaultFractionDigits(format, symbols);
    }

    return format;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:NumberFormatProviderImpl.java

示例2: test2

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
public static void test2(DecimalFormat df) {
	int number = 155566;
	//默認整數部分三個一組,
	System.out.println(number);//輸出格式155,566
	//設置每四個一組
	df.setGroupingSize(4);
	System.out.println(df.format(number));//輸出格式為15,5566
	DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance();
	//設置小數點分隔符
	dfs.setDecimalSeparator(';');
	//設置分組分隔符
	dfs.setGroupingSeparator('a');
	df.setDecimalFormatSymbols(dfs);
	System.out.println(df.format(number));//15a5566
	System.out.println(df.format(11.22));//11;22
	//取消分組
	df.setGroupingUsed(false);
	System.out.println(df.format(number));
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:20,代碼來源:TestDecimalFormat.java

示例3: placeOrder

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
/**
 * Purchase something
 *
 * @param currencyMarketId the market on which to purchase
 * @param amount           the amount to buy
 * @param ppc              the price expected
 * @param category         trade-kind purchase or sale
 * @return the order confirmation
 */
public OrderData placeOrder(long currencyMarketId, double amount, double ppc, PurchaseCategory category) throws HashnestServiceException {
    NumberFormat nmbrFmt = new DecimalFormat("0.########", DecimalFormatSymbols.getInstance(Locale.US));

    Map<String, String> signature = keyGen.signature();
    signature.put("currency_market_id", String.valueOf(currencyMarketId));
    signature.put("amount", nmbrFmt.format(amount));
    signature.put("ppc", nmbrFmt.format(ppc));
    signature.put("category", category.code);

    ResponseEntity<String> response = callHashnestWithRetry(signature, String.class, API_GET_ORDERS_EXECUTE, "execute order");

    if (response == null) return null;

    OrderData orderData = null;

    if (response.getBody() != null && response.getStatusCodeValue() == 201) {
        log.debug("received order execution body as response: {}", response.getBody());

        ObjectMapper mapper = new ObjectMapper();
        try {
            orderData = mapper.readValue(response.getBody(), OrderData.class);
            log.debug("OrderData received, order has been placed {}", orderData);
        } catch (Exception e) {
            throw new HashnestServiceException(format("order failed to execute %s", response.getBody()));
        }
    }

    return orderData;
}
 
開發者ID:asciimo71,項目名稱:hashnest,代碼行數:39,代碼來源:HashnestServiceClient.java

示例4: formatSeconds

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
/**
 * Formats seconds
 * @param seconds the number of seconds to format
 * @return a string formatted with a different unit depending on the number of seconds
 */
private String formatSeconds(int seconds) {
    String time;
    DecimalFormat decimal = new DecimalFormat("0.0", DecimalFormatSymbols.getInstance(Locale.getDefault()));
    DecimalFormat integer = new DecimalFormat("0");

    float min = seconds / 60.0f;
    float hour = min / 60.0f;

    if(hour > 1) {
        time = hasDecimal(hour) ? decimal.format(hour).concat(" h") : integer.format(hour).concat(" h");
    } else if(min > 1) {
        time = hasDecimal(min) ? decimal.format(min).concat(" m") : integer.format(min).concat(" m");
    } else {
        time = integer.format(seconds).concat(" s");
    }

    return time;
}
 
開發者ID:bamless,項目名稱:chromium-swe-updater,代碼行數:24,代碼來源:ProgressNotification.java

示例5: format

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
public static String format(long amountValue, int exponent, Locale locale) {
    String valueString;
    if (exponent > 0) {
        final String sign = (amountValue < 0) ? "-" : "";
        long absAmountValue = Math.abs(amountValue);
        long power = 1;
        for (int i = 0; i < exponent; i++) {
            power *= 10;
        }
        if (locale != null) {
            DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(locale);
            String highValue = NumberFormat.getInstance(locale).format((absAmountValue / power));
            valueString = String.format("%s%s%s%0" + exponent + "d", sign, highValue, dfs.getDecimalSeparator(),
                    (absAmountValue % power));
        } else {
            valueString = String.format("%s%d.%0" + exponent + "d", sign, (absAmountValue / power),
                    (absAmountValue % power));
        }
    } else {
        if (locale != null) {
            valueString = NumberFormat.getInstance(locale).format(amountValue);
        } else {
            valueString = String.valueOf(amountValue);
        }
    }
    return valueString;
}
 
開發者ID:Adyen,項目名稱:adyen-android,代碼行數:28,代碼來源:AmountUtil.java

示例6: prettyPrint

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
/**
 * Pretty prints a double value (with maximal necessary precision or as integer, if so).
 *
 * @param value
 * @return
 */
public static String prettyPrint(double value) {
    /*
    To remove - sign if value is zero
     */
    if (Double.compare(-0d, value) == 0) {
        value *= -1d;
    }
    /*
    Solution by: http://stackoverflow.com/a/25308216
     */
    DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
    df.setMaximumFractionDigits(340); //340 = DecimalFormat.DOUBLE_FRACTION_DIGITS
    return df.format(value);
}
 
開發者ID:dbisUnibas,項目名稱:ReqMan,代碼行數:21,代碼來源:StringUtils.java

示例7: getSearchSpaceScientific

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
/**
 * @return the approximate solution space as a string formatted in
 * scientific notation
 */
public String getSearchSpaceScientific() {
	BigInteger solSpace = getSearchSpace();
	String solSpaceScientific = solSpace.toString();
	if (solSpace.compareTo(BigInteger.valueOf(100000)) > 0) {
		NumberFormat formatter = new DecimalFormat("0.######E0", DecimalFormatSymbols.getInstance(Locale.ROOT));
		solSpaceScientific = formatter.format(solSpace);
	}
	return solSpaceScientific;
}
 
開發者ID:bamless,項目名稱:Fork-join-sudoku-solver,代碼行數:14,代碼來源:SudokuBoard.java

示例8: initSettings

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
/***
 * If user does not provide a valid locale it throws IllegalArgumentException.
 *
 * If throws an IllegalArgumentException the locale sets to default locale
 */
private void initSettings() {
    boolean success = false;
    while (!success) {
        try {
            fractionDigit = Currency.getInstance(locale).getDefaultFractionDigits();

            DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(locale);
            if (mGroupDivider > 0)
                symbols.setGroupingSeparator(mGroupDivider);
            groupDivider = symbols.getGroupingSeparator();

            if (mMonetaryDivider > 0)
                symbols.setMonetaryDecimalSeparator(mMonetaryDivider);
            monetaryDivider = symbols.getMonetaryDecimalSeparator();

            currencySymbol = symbols.getCurrencySymbol();

            DecimalFormat df = (DecimalFormat) DecimalFormat.getCurrencyInstance(locale);
            numberFormat = new DecimalFormat(df.toPattern(), symbols);

            success = true;
        } catch (IllegalArgumentException e) {
            Log.e(getClass().getCanonicalName(), e.getMessage());
            locale = getDefaultLocale();
        }
    }
}
 
開發者ID:FranciscoJavierPRamos,項目名稱:Android-FilterView,代碼行數:33,代碼來源:CurrencyEditText.java

示例9: formatValue

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
@Override
public String formatValue(String key, Object value) {
    if (key.equals(Command.KEY_TIMEZONE)) {
        double offset = TimeZone.getTimeZone((String) value).getRawOffset() / 3600000.0;
        DecimalFormat fmt = new DecimalFormat("+#.##;-#.##", DecimalFormatSymbols.getInstance(Locale.US));
        return fmt.format(offset);
    }

    return null;
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:11,代碼來源:WatchProtocolEncoder.java

示例10: create

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
private static DecimalStyle create(Locale locale) {
    DecimalFormatSymbols oldSymbols = DecimalFormatSymbols.getInstance(locale);
    char zeroDigit = oldSymbols.getZeroDigit();
    char positiveSign = '+';
    char negativeSign = oldSymbols.getMinusSign();
    char decimalSeparator = oldSymbols.getDecimalSeparator();
    if (zeroDigit == '0' && negativeSign == '-' && decimalSeparator == '.') {
        return STANDARD;
    }
    return new DecimalStyle(zeroDigit, positiveSign, negativeSign, decimalSeparator);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:12,代碼來源:DecimalStyle.java

示例11: getZero

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
private static char getZero(Locale l) {
    if ((l != null) && !l.equals(Locale.US)) {
        DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(l);
        return dfs.getZeroDigit();
    } else {
        return '0';
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:9,代碼來源:Formatter.java

示例12: HashnestUtils

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
public HashnestUtils() {
    formatBtcNmbr = new DecimalFormat("0.00000000", DecimalFormatSymbols.getInstance(Locale.US));
    formatSatNmbr = new DecimalFormat("#,###.##", DecimalFormatSymbols.getInstance(Locale.US));
}
 
開發者ID:asciimo71,項目名稱:hashnest,代碼行數:5,代碼來源:HashnestUtils.java

示例13: checkDigit

import java.text.DecimalFormatSymbols; //導入方法依賴的package包/類
private void checkDigit(Locale loc, Character expected) {
    DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(loc);
    Character zero = dfs.getZeroDigit();
    assertEquals("Wrong digit zero char", expected, zero);
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:6,代碼來源:LocaleEnhanceTest.java


注:本文中的java.text.DecimalFormatSymbols.getInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。