• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AmountFormatQueryBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createAmountFormatQuery

import javax.money.format.AmountFormatQueryBuilder; //导入依赖的package包/类
private static AmountFormatQuery createAmountFormatQuery(FormatSpec specAnnot, AmountSpec amountSpec) {
    AmountFormatQueryBuilder b = AmountFormatQueryBuilder.of(specAnnot.name());
    if(specAnnot.providers().length>0){
        b.setProviderNames(specAnnot.providers());
    }
    if(specAnnot.attributes().length>0){
        applyAttributes(specAnnot.attributes(), b);
    }
    if(!specAnnot.locale().isEmpty()){
        b.setLocale(createLocale(specAnnot.locale()));
    }else{
        // Required to avoid NOE, see https://github.com/JavaMoney/jsr354-ri/issues/156
        b.setLocale(Locale.getDefault());
    }
    if(amountSpec!=null){
        b.setMonetaryAmountFactory(Monetary.getAmountFactory(createAmountQuery(amountSpec)));
    }
    return b.build();
}
 
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:20,代码来源:MonetaryProducer.java


示例2: testWithCustomPattern

import javax.money.format.AmountFormatQueryBuilder; //导入依赖的package包/类
/**
 * Test related to {@link https://java.net/jira/browse/JAVAMONEY-92}.
 */
@Test
public void testWithCustomPattern() {
    MonetaryAmountFormat format = MonetaryFormats.getAmountFormat(
            AmountFormatQueryBuilder.of(Locale.GERMANY)
                    .set(CurrencyStyle.SYMBOL)
                    .set("pattern", "#,##0.00### ¤")
                    .build());
    Money money = Money.of(12345.23456789, "EUR");
    assertEquals("12.345,23457 €", format.format(money));

    format = MonetaryFormats.getAmountFormat(
            AmountFormatQueryBuilder.of(Locale.GERMANY)
                    .set(CurrencyStyle.SYMBOL)
                    .build());
    assertEquals("12.345,23 €", format.format(money));


}
 
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:22,代码来源:MonetaryAmountFormatTest.java


示例3: main

import javax.money.format.AmountFormatQueryBuilder; //导入依赖的package包/类
public static void main(String[] args) {
	CurrencyUnit dollar = Monetary.getCurrency(Locale.US);
	
	MonetaryAmount monetaryAmount = Money.of(1202.12D, dollar);
	MonetaryAmountFormat germanFormat = MonetaryFormats.getAmountFormat(
			Locale.GERMANY);
	MonetaryAmountFormat usFormat = MonetaryFormats.getAmountFormat(
			Locale.US);
	 MonetaryAmountFormat customFormat = MonetaryFormats.getAmountFormat(
                AmountFormatQueryBuilder.of(Locale.US).setFormatName("SYMBOL").build());
	 
	System.out.println(germanFormat.format(monetaryAmount));//1.202,12 USD
	System.out.println(usFormat.format(monetaryAmount));//USD1,202.12
	System.out.println(customFormat.format(monetaryAmount));//$1,202.12
	
	 
}
 
开发者ID:JavaMoney,项目名称:javamoney-examples,代码行数:18,代码来源:FormatExample.java


示例4: main

import javax.money.format.AmountFormatQueryBuilder; //导入依赖的package包/类
public static void main(String[] args) {
	MonetaryAmount amount = Money.of(12345.67, "USD");
	MonetaryAmountFormat customFormat = MonetaryFormats.getAmountFormat(
			AmountFormatQueryBuilder.of(Locale.US)
			.set(CurrencyStyle.NAME)
			.set("pattern", "00,00,00,00.00 ¤")
			.build()); 

			String formatted = customFormat.format(amount); //00,01,23,45.67 US Dollar
}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:11,代码来源:MonetaryFormatsExampleQueryCustom.java


示例5: format

import javax.money.format.AmountFormatQueryBuilder; //导入依赖的package包/类
@Override
public String format(final MonetaryAmount monetaryAmount) {
    final boolean isDecimal = monetaryAmount.getNumber().doubleValueExact() % 1 != 0;//TODO this can be improved with monetary query
    final AmountFormatQuery pattern = AmountFormatQueryBuilder.of(locale)
            .set(CurrencyStyle.SYMBOL)
            .set(PATTERN, isDecimal ? PATTERN_WITH_DECIMAL : PATTERN_WITHOUT_DECIMAL)
            .build();
    return MonetaryFormats.getAmountFormat(pattern).format(monetaryAmount);
}
 
开发者ID:commercetools,项目名称:commercetools-sunrise-java,代码行数:10,代码来源:PriceFormatterImpl.java


示例6: testFormatWithBuilder

import javax.money.format.AmountFormatQueryBuilder; //导入依赖的package包/类
/**
 * Test method for
 * {@link javax.money.format.MonetaryAmountFormat#format(javax.money.MonetaryAmount)} .
 */
@Test
public void testFormatWithBuilder() {
    MonetaryAmountFormat defaultFormat =
            MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder.of(Locale.JAPANESE).build());
    assertEquals("CHF 12.50", defaultFormat
            .format(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(12.50)
                    .create()));
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:13,代码来源:MonetaryAmountFormatTest.java


示例7: testFormatWithBuilder2

import javax.money.format.AmountFormatQueryBuilder; //导入依赖的package包/类
/**
 * Test method for
 * {@link javax.money.format.MonetaryAmountFormat#format(javax.money.MonetaryAmount)} .
 */
@Test
public void testFormatWithBuilder2() {
    MonetaryAmountFormat format = MonetaryFormats
            .getAmountFormat(AmountFormatQueryBuilder.of(Locale.GERMANY).set(CurrencyStyle.NUMERIC_CODE).build());
    assertEquals("12,50 756", format.format(
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(12.50).create()));
    format = MonetaryFormats
            .getAmountFormat(AmountFormatQueryBuilder.of(Locale.US).set(CurrencyStyle.SYMBOL).build());
    assertEquals("$123,456.56", format.format(
            Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(123456.561)
                    .create()));
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:17,代码来源:MonetaryAmountFormatTest.java


示例8: main

import javax.money.format.AmountFormatQueryBuilder; //导入依赖的package包/类
public static void main(String... args) {
    MonetaryAmount amt = Money.of(1234.5678, "EUR");
    System.out.println(amt.query(MonetaryFormats.getAmountFormat(Locale.GERMANY)));
    System.out.println(MonetaryFormats.getAmountFormat(Locale.GERMANY).format(amt));
    amt = Money.of(123412341234.5678, "INR");
    System.out.println(MonetaryFormats.getAmountFormat(new Locale("", "INR")).format(amt));

    // no with adaptive groupings
    System.out.println(MonetaryFormats.getAmountFormat(
            AmountFormatQueryBuilder.of(new Locale("", "INR"))
                    .set(AmountFormatParams.GROUPING_SIZES, new int[]{2, 3})
                    .set(AmountFormatParams.GROUPING_GROUPING_SEPARATORS, new char[]{',', '`'})
                    .build())
            .format(amt));
}
 
开发者ID:JavaMoney,项目名称:javamoney-examples,代码行数:16,代码来源:FormattingAmounts.java


示例9: main

import javax.money.format.AmountFormatQueryBuilder; //导入依赖的package包/类
public static void main(String[] args) {
    CurrencyUnit currency = Monetary.getCurrency("USD");
    MonetaryAmount money = Money.of(12, currency);

    MonetaryAmountFormat format = MonetaryFormats
                    .getAmountFormat(AmountFormatQueryBuilder.of(Locale.US).set(CurrencyStyle.SYMBOL).build());


    String resultText = format.format(money);//$12.00
}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:11,代码来源:MonetaryFormatsExampleQuery.java


示例10: getAmountFormat

import javax.money.format.AmountFormatQueryBuilder; //导入依赖的package包/类
/**
 * Access the default {@link javax.money.format.MonetaryAmountFormat} given a {@link java.util.Locale}.
 *
 * @param locale    the target {@link java.util.Locale}, not {@code null}.
 * @param providers The (optional) providers to be used, oredered correspondingly.
 * @return the matching {@link javax.money.format.MonetaryAmountFormat}
 * @throws javax.money.MonetaryException if no registered {@link javax.money.spi.MonetaryAmountFormatProviderSpi} can provide a
 *                           corresponding {@link javax.money.format.MonetaryAmountFormat} instance.
 */
public MonetaryAmountFormat getAmountFormat(Locale locale, String... providers) {
    return getAmountFormat(AmountFormatQueryBuilder.of(locale).setProviderNames(providers).build());
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:13,代码来源:BaseMonetaryFormatsSingletonSpi.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RemoteDebuggerClient类代码示例发布时间:2022-05-23
下一篇:
Java ParseUtils类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap