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


Java RuleBasedNumberFormat类代码示例

本文整理汇总了Java中com.ibm.icu.text.RuleBasedNumberFormat的典型用法代码示例。如果您正苦于以下问题:Java RuleBasedNumberFormat类的具体用法?Java RuleBasedNumberFormat怎么用?Java RuleBasedNumberFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: formatRuleBasedAmount

import com.ibm.icu.text.RuleBasedNumberFormat; //导入依赖的package包/类
/**
 * Method to format an amount using a custom rule set.
 * Current rule sets available:
 *
 * en_US
 * %dollars-and-cents - 1,225.25 becomes "one thousand two hundred twenty five dollars and twenty five cents" (useful for checks)
 * %dollars-and-hundreths - 1,225.25 becomes "one thousand two hundred twenty five and 25/00" (alternate for checks)
 *
 * @param   amount - the amount to format
 * @param   rule - the name of the rule set to use (e.g., %dollars-and-hundredths)
 * @param   locale - the Locale
 * @return  formatted string or an empty string if there was an error
 */
public static String formatRuleBasedAmount(double amount, String rule, Locale locale) {
    String ruleSet = rbnfRuleSets.get(locale);
    if (ruleSet == null) {
        Debug.logWarning("Cannot format rule based amount for locale " + locale.toString() + " because rule set for that locale does not exist", module);
        return "";
    }
    RuleBasedNumberFormat formatter = new RuleBasedNumberFormat(ruleSet, locale);
    String result = "";
    try {
        result = formatter.format(amount, rule);
    } catch (Exception e) {
        Debug.logError(e, "Failed to format amount " + amount + " using rule " + rule, module);
    }
    return result;
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:29,代码来源:UtilNumber.java

示例2: getOrdinalRuleName

import com.ibm.icu.text.RuleBasedNumberFormat; //导入依赖的package包/类
/**
 * Try to extract the rule name for "expand ordinal" from the given RuleBasedNumberFormat.
 * <p/>
 * The rule name is locale sensitive, but usually starts with "%spellout-ordinal".
 *
 * @param rbnf
 *            The RuleBasedNumberFormat from where we will try to extract the rule name.
 * @return The rule name for "ordinal spell out".
 */
protected String getOrdinalRuleName(final RuleBasedNumberFormat rbnf) {
	List<String> l = Arrays.asList(rbnf.getRuleSetNames());
	System.err.println("RNBF list for 'ar':"+l);
	//[%spellout-cardinal-masculine, %spellout-cardinal-feminine, %spellout-numbering, %spellout-numbering-year]
	//But http://unicode.org/repos/cldr/trunk/common/rbnf/ar.xml has spellout-ordinal-masculine and spellout-ordinal-feminine
	if (l.contains("%spellout-ordinal")) {
		return "%spellout-ordinal";
	} else {
		for (String string : l) {
			if (string.startsWith("%spellout-ordinal")) {
				return string;
			}
		}
	}
	throw new UnsupportedOperationException("The locale " + rbnf.getLocale(ULocale.ACTUAL_LOCALE)
			+ " doesn't support ordinal spelling.");
}
 
开发者ID:HaraldBerthelsen,项目名称:marytts-lang-ar,代码行数:27,代码来源:Preprocess.java

示例3: check

import com.ibm.icu.text.RuleBasedNumberFormat; //导入依赖的package包/类
@Override
public void check(Placeholder target, ULocale locale, String message) {
  List<NumberFormat> formatters = ImmutableList.of(NumberFormat.getCurrencyInstance(locale),
      NumberFormat.getInstance(locale),
      NumberFormat.getIntegerInstance(locale),
      NumberFormat.getNumberInstance(locale),
      NumberFormat.getPercentInstance(locale),
      NumberFormat.getScientificInstance(locale),
      new RuleBasedNumberFormat(locale, RuleBasedNumberFormat.SPELLOUT),
      new RuleBasedNumberFormat(locale, RuleBasedNumberFormat.ORDINAL),
      new RuleBasedNumberFormat(locale, RuleBasedNumberFormat.DURATION),
      new RuleBasedNumberFormat(locale, RuleBasedNumberFormat.NUMBERING_SYSTEM));

  check(formatters, target, locale, message);
}
 
开发者ID:googlei18n,项目名称:i18n_sanitycheck,代码行数:16,代码来源:NumberChecker.java

示例4: IcuNumberFormatTokenFilterFactory

import com.ibm.icu.text.RuleBasedNumberFormat; //导入依赖的package包/类
public IcuNumberFormatTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name,
                                         Settings settings) {
    super(indexSettings, name, settings);
    this.locale = settings.get("locale") != null ? new ULocale(settings.get("locale")) : ULocale.getDefault();
    String formatStr = settings.get("format", "SPELLOUT");
    switch (formatStr.toUpperCase()) {
        case "DURATION":
            format = RuleBasedNumberFormat.DURATION;
            break;
        case "NUMBERING_SYSTEM":
            format = RuleBasedNumberFormat.NUMBERING_SYSTEM;
            break;
        case "NUMBERSTYLE":
            format = RuleBasedNumberFormat.NUMBERSTYLE;
            break;
        case "ORDINAL":
            format = RuleBasedNumberFormat.ORDINAL;
            break;
        case "SPELLOUT":
        default:
            format = RuleBasedNumberFormat.SPELLOUT;
            break;
    }
    // RBNF parsing is incredibly slow when lenient is enabled but the only method to parse compound number words
    this.lenient = settings.getAsBoolean("lenient", true);
    this.grouping = settings.getAsBoolean("grouping", true);
}
 
开发者ID:jprante,项目名称:elasticsearch-plugin-bundle,代码行数:28,代码来源:IcuNumberFormatTokenFilterFactory.java

示例5: create

import com.ibm.icu.text.RuleBasedNumberFormat; //导入依赖的package包/类
@Override
public TokenStream create(TokenStream tokenStream) {
    // create a new number format instance for each token stream
    RuleBasedNumberFormat ruleBasedNumberFormat = new RuleBasedNumberFormat(locale, format);
    ruleBasedNumberFormat.setLenientParseMode(lenient);
    ruleBasedNumberFormat.setGroupingUsed(grouping);
    return new IcuNumberFormatTokenFilter(tokenStream, ruleBasedNumberFormat);
}
 
开发者ID:jprante,项目名称:elasticsearch-plugin-bundle,代码行数:9,代码来源:IcuNumberFormatTokenFilterFactory.java

示例6: Preprocess

import com.ibm.icu.text.RuleBasedNumberFormat; //导入依赖的package包/类
public Preprocess() {
super("Preprocess", MaryDataType.TOKENS, MaryDataType.WORDS, new Locale("ar"));
this.rbnf = new RuleBasedNumberFormat(new ULocale("ar"), RuleBasedNumberFormat.SPELLOUT);
this.cardinalRule = "%spellout-numbering";
//this.ordinalRule = getOrdinalRuleName(rbnf);
   }
 
开发者ID:HaraldBerthelsen,项目名称:marytts-lang-ar,代码行数:7,代码来源:Preprocess.java

示例7: spellOutInMarathi

import com.ibm.icu.text.RuleBasedNumberFormat; //导入依赖的package包/类
private static String spellOutInMarathi(BigDecimal number) {
    RuleBasedNumberFormat formatter = new RuleBasedNumberFormat(MARATHI_SPELLOUT_RULES);
    return formatter.format(number);
}
 
开发者ID:sahilm,项目名称:format-numbers-in-marathi,代码行数:5,代码来源:NumberFormat.java


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