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


Java MonetaryAmountFormat类代码示例

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


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

示例1: getAmountFormats

import javax.money.format.MonetaryAmountFormat; //导入依赖的package包/类
@Override
public Collection<MonetaryAmountFormat> getAmountFormats(AmountFormatQuery amountFormatQuery) {
    Objects.requireNonNull(amountFormatQuery, "AmountFormatContext required");
    if (!amountFormatQuery.getProviderNames().isEmpty() &&
            !amountFormatQuery.getProviderNames().contains(getProviderName())) {
        return Collections.emptySet();
    }
    if (!(amountFormatQuery.getFormatName() == null || DEFAULT_FORMAT.equals(amountFormatQuery.getFormatName()))) {
        return Collections.emptySet();
    }
    AmountFormatContextBuilder builder = AmountFormatContextBuilder.of(DEFAULT_FORMAT);
    if (amountFormatQuery.getLocale() != null) {
        builder.setLocale(amountFormatQuery.getLocale());
    }
    builder.importContext(amountFormatQuery, false);
    builder.setMonetaryAmountFactory(amountFormatQuery.getMonetaryAmountFactory());
    return Arrays.asList(new MonetaryAmountFormat[]{new DefaultMonetaryAmountFormat(builder.build())});
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri-bp,代码行数:19,代码来源:DefaultAmountFormatProviderSpi.java

示例2: getAmountFormats

import javax.money.format.MonetaryAmountFormat; //导入依赖的package包/类
@Override
public Collection<MonetaryAmountFormat> getAmountFormats(AmountFormatQuery amountFormatQuery) {
    Objects.requireNonNull(amountFormatQuery, "AmountFormatContext required");
    if (!amountFormatQuery.getProviderNames().isEmpty() &&
            !amountFormatQuery.getProviderNames().contains(getProviderName())) {
        return Collections.emptySet();
    }
    if (!(amountFormatQuery.getFormatName() == null || DEFAULT_STYLE.equals(amountFormatQuery.getFormatName()))) {
        return Collections.emptySet();
    }
    AmountFormatContextBuilder builder = AmountFormatContextBuilder.of(DEFAULT_STYLE);
    if (amountFormatQuery.getLocale() != null) {
        builder.setLocale(amountFormatQuery.getLocale());
    }
    builder.importContext(amountFormatQuery, false);
    builder.setMonetaryAmountFactory(amountFormatQuery.getMonetaryAmountFactory());
    return Arrays.asList(new MonetaryAmountFormat[]{new DefaultMonetaryAmountFormat(builder.build())});
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:19,代码来源:DefaultAmountFormatProviderSpi.java

示例3: testFormat

import javax.money.format.MonetaryAmountFormat; //导入依赖的package包/类
/**
 * Test method for
 * {@link javax.money.format.MonetaryAmountFormat#format(javax.money.MonetaryAmount)} .
 */
@Test
public void testFormat() {
    MonetaryAmountFormat defaultFormat = MonetaryFormats.getAmountFormat(Locale.GERMANY);
    assertEquals("12,50 CHF", defaultFormat
            .format(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(12.50)
                    .create()));
    assertEquals("123.456.789.101.112,12 INR", defaultFormat
            .format(Monetary.getDefaultAmountFactory().setCurrency("INR")
                    .setNumber(123456789101112.123456).create()));
    defaultFormat = MonetaryFormats.getAmountFormat(new Locale("", "IN"));
    assertEquals("CHF 1,211,112.50", defaultFormat
            .format(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(1211112.50)
                    .create()));
    assertEquals("INR 123,456,789,101,112.12", defaultFormat
            .format(Monetary.getDefaultAmountFactory().setCurrency("INR")
                    .setNumber(123456789101112.123456).create()));
    // Locale india = new Locale("", "IN");
    // defaultFormat = MonetaryFormats.getAmountFormatBuilder(india)
    // .setNumberGroupSizes(3, 2).of();
    // assertEquals("INR 12,34,56,78,91,01,112.12",
    // defaultFormat.format(Monetary.getAmount("INR",
    // 123456789101112.123456)));
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:28,代码来源:MonetaryAmountFormatTest.java

示例4: testWithCustomPattern

import javax.money.format.MonetaryAmountFormat; //导入依赖的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

示例5: main

import javax.money.format.MonetaryAmountFormat; //导入依赖的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

示例6: main

import javax.money.format.MonetaryAmountFormat; //导入依赖的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

示例7: main

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

    MonetaryAmountFormat format =
            MonetaryFormats.getAmountFormat(Locale.US);

    String resultText = format.format(money);//EUR 12
    MonetaryAmount monetaryAmount = format.parse(resultText);
    MonetaryAmount result2 = Money.parse(resultText, format);

}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:13,代码来源:MonetaryFormatsExample.java

示例8: main

import javax.money.format.MonetaryAmountFormat; //导入依赖的package包/类
public static void main(String[] args) {
	MonetaryAmountFormat defaultFormat = MonetaryAmountDecimalFormatBuilder.newInstance().build();
	MonetaryAmountFormat patternFormat = MonetaryAmountDecimalFormatBuilder.of("¤ ###,###.00").build();
	MonetaryAmountFormat localeFormat = MonetaryAmountDecimalFormatBuilder.of(Locale.US).build();
	
    CurrencyUnit currency = Monetary.getCurrency("BRL");
    MonetaryAmount money = Money.of(12, currency);
    String format = defaultFormat.format(money);//$12.00
    MonetaryAmount moneyParsed = Money.parse(format, defaultFormat);//or using defafult.parse(format);

}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:12,代码来源:MonetaryAmountDecimalFormatBuilderExample.java

示例9: main

import javax.money.format.MonetaryAmountFormat; //导入依赖的package包/类
public static void main(String[] args) {
	MonetaryAmountFormat patternFormat = MonetaryAmountDecimalFormatBuilder.of("¤ ###,###.00").build();
	
    CurrencyUnit currency = Monetary.getCurrency("BRL");
    MonetaryAmount money = Money.of(12, currency);
    String format = patternFormat.format(money);//$ 12.00
    MonetaryAmount moneyParsed = Money.parse(format, patternFormat);//or using defafult.parse(format);

}
 
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:10,代码来源:MonetaryAmountDecimalFormatBuilderExample3.java

示例10: amountFormat

import javax.money.format.MonetaryAmountFormat; //导入依赖的package包/类
@Produces @Dependent
public static MonetaryAmountFormat amountFormat(InjectionPoint ip){
    FormatSpec specAnnot = ip.getAnnotated()!=null?ip.getAnnotated().getAnnotation(FormatSpec.class):null;
    if(specAnnot==null){
        throw new IllegalArgumentException("@FormatName is required.");
    }
    return MonetaryFormats.getAmountFormat(createAmountFormatQuery(
            specAnnot,
            ip.getAnnotated().getAnnotation(AmountSpec.class)));
}
 
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:11,代码来源:MonetaryProducer.java

示例11: amountFormats

import javax.money.format.MonetaryAmountFormat; //导入依赖的package包/类
@Produces @Dependent
public static Collection<MonetaryAmountFormat> amountFormats(InjectionPoint ip){
    FormatSpec specAnnot = ip.getAnnotated()!=null?ip.getAnnotated().getAnnotation(FormatSpec.class):null;
    if(specAnnot==null){
        throw new IllegalArgumentException("@FormatName is required.");
    }
    return MonetaryFormats.getAmountFormats(createAmountFormatQuery(
            specAnnot,
            ip.getAnnotated().getAnnotation(AmountSpec.class)));
}
 
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:11,代码来源:MonetaryProducer.java

示例12: testAmountFormatRoundTrip

import javax.money.format.MonetaryAmountFormat; //导入依赖的package包/类
@Test
public void testAmountFormatRoundTrip() throws ParseException {
    // Using parsers
    MonetaryAmountFormat format = MonetaryFormats.getAmountFormat(Locale.GERMANY);
    assertNotNull(format);
    MonetaryAmount amount = Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(10.50).create();
    String formatted = format.format(amount);
    assertNotNull(formatted);
    MonetaryAmount parsed = format.parse(formatted);
    assertNotNull(parsed);
    assertEquals(amount, parsed);
}
 
开发者ID:JavaMoney,项目名称:javamoney-lib,代码行数:13,代码来源:SmokeTest.java

示例13: testFormatWithBuilder

import javax.money.format.MonetaryAmountFormat; //导入依赖的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

示例14: testFormatWithBuilder2

import javax.money.format.MonetaryAmountFormat; //导入依赖的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

示例15: testPrint

import javax.money.format.MonetaryAmountFormat; //导入依赖的package包/类
/**
 * Test method for
 * {@link javax.money.format.MonetaryAmountFormat#print(java.lang.Appendable, javax.money.MonetaryAmount)}
 * .
 *
 * @throws IOException
 */
@Test
public void testPrint() throws IOException {
    StringBuilder b = new StringBuilder();
    MonetaryAmountFormat defaultFormat = MonetaryFormats.getAmountFormat(Locale.GERMANY);
    defaultFormat.print(b, Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(12.50).create());
    assertEquals("12,50 CHF", b.toString());
    b.setLength(0);
    defaultFormat.print(b, Monetary.getDefaultAmountFactory().setCurrency("INR")
            .setNumber(123456789101112.123456).create());
    assertEquals("123.456.789.101.112,12 INR", b.toString());
    b.setLength(0);
    defaultFormat = MonetaryFormats.getAmountFormat(new Locale("", "IN"));
    defaultFormat
            .print(b, Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(1211112.50).create());
    assertEquals("CHF 1,211,112.50", b.toString());
    b.setLength(0);
    defaultFormat.print(b, Monetary.getDefaultAmountFactory().setCurrency("INR")
            .setNumber(123456789101112.123456).create());
    assertEquals("INR 123,456,789,101,112.12", b.toString());
    b.setLength(0);
    // Locale india = new Locale("", "IN");
    // defaultFormat = MonetaryFormats.getAmountFormat(india)
    // .setNumberGroupSizes(3, 2).of();
    // defaultFormat.print(b, Monetary.getAmount("INR",
    // 123456789101112.123456));
    // assertEquals("INR 12,34,56,78,91,01,112.12",
    // b.toString());
}
 
开发者ID:JavaMoney,项目名称:jsr354-ri,代码行数:36,代码来源:MonetaryAmountFormatTest.java


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