当前位置: 首页>>代码示例>>Java>>正文


Java NumberFormat.getScientificInstance方法代码示例

本文整理汇总了Java中com.ibm.icu.text.NumberFormat.getScientificInstance方法的典型用法代码示例。如果您正苦于以下问题:Java NumberFormat.getScientificInstance方法的具体用法?Java NumberFormat.getScientificInstance怎么用?Java NumberFormat.getScientificInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.ibm.icu.text.NumberFormat的用法示例。


在下文中一共展示了NumberFormat.getScientificInstance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: guessNumberFormat

import com.ibm.icu.text.NumberFormat; //导入方法依赖的package包/类
/**
 * This function can be overridden by subclasses to use different heuristics.
 * <b>It MUST return a 'safe' value,
 * one whose modification will not affect this object.</b>
 *
 * @param style
 * @draft ICU 3.6
 * @provisional This API might change or be removed in a future release.
 */
protected NumberFormat guessNumberFormat(int style) {
    NumberFormat result;
    ULocale nfLocale = getAvailableLocale(TYPE_NUMBERFORMAT);
    if (nfLocale == null) {
        nfLocale = ULocale.ROOT;
    }
    switch (style) {
    case NF_NUMBER:
        result = NumberFormat.getInstance(nfLocale);
        break;
    case NF_SCIENTIFIC:
        result = NumberFormat.getScientificInstance(nfLocale);
        break;
    case NF_INTEGER:
        result = NumberFormat.getIntegerInstance(nfLocale);
        break;
    case NF_PERCENT:
        result = NumberFormat.getPercentInstance(nfLocale);
        break;
    case NF_CURRENCY:
        result = NumberFormat.getCurrencyInstance(nfLocale);
        result.setCurrency(getCurrency());
        break;
    default:
        throw new IllegalArgumentException("Unknown number format style");
    }
    return result;
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:38,代码来源:GlobalizationPreferences.java

示例2: formatNumber

import com.ibm.icu.text.NumberFormat; //导入方法依赖的package包/类
public String formatNumber(final Number n, final LotusNumberOptions lno) {
	NumberFormat nf;
	/*
	 * It would have been more convenient to use NumberFormat.getInstance(locale, style),
	 * but this method is private in com.ibm.icu_3.8.1.v20120530.jar.
	 * (Seems to be public as of ICU 4.2.)
	 */
	if (lno.format == 'C')
		nf = NumberFormat.getCurrencyInstance(iLocale);
	else if (lno.format == 'S')
		nf = NumberFormat.getScientificInstance(iLocale);
	else if (lno.format == '%')
		nf = NumberFormat.getPercentInstance(iLocale);
	else
		nf = NumberFormat.getNumberInstance(iLocale);
	nf.setGroupingUsed(lno.useGrouping);
	nf.setMaximumIntegerDigits(1000);
	if (lno.fractionDigits != -1) {
		nf.setMinimumFractionDigits(lno.fractionDigits);
		nf.setMaximumFractionDigits(lno.fractionDigits);
	} else
		nf.setMaximumFractionDigits(1000);
	String ret = nf.format(n);
	do {
		if (lno.format != 'G' || ret.length() <= 15)
			break;
		/*
		 * In this case, Lotus implicitly switches to scientific style.
		 * When useGrouping is in effect, the limit decreases from 15 to 12 in Lotus
		 * (i.e. the grouping bytes are likewise counted), but we are not going to
		 *  imitate this strange behaviour.
		 */
		String tester = ret;
		if (lno.useGrouping) {
			nf.setGroupingUsed(false);
			tester = nf.format(n);
		}
		int minus = (tester.charAt(0) == '-') ? 1 : 0;
		int lh = tester.length();
		if (lh - minus <= 15)
			break;
		int komma = minus;
		for (; komma < lh; komma++)
			if (!Character.isDigit(tester.charAt(komma)))
				break;
		if (komma - minus <= 15)
			break;
		nf = NumberFormat.getScientificInstance(iLocale);
		nf.setGroupingUsed(lno.useGrouping);
		ret = nf.format(n);
	} while (false);
	if (lno.negativeAsParentheses && ret.charAt(0) == '-')
		ret = '(' + ret.substring(1) + ')';
	return ret;
}
 
开发者ID:OpenNTF,项目名称:org.openntf.domino,代码行数:56,代码来源:FormatterImpl.java


注:本文中的com.ibm.icu.text.NumberFormat.getScientificInstance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。