Search in sources :

Example 21 with AmountFormatQuery

use of javax.money.format.AmountFormatQuery in project jsr354-ri by JavaMoney.

the class MonetaryFormatsTest method testParse_CNY_zh_CN.

@Test
public void testParse_CNY_zh_CN() {
    AmountFormatQuery formatQuery = AmountFormatQueryBuilder.of(CHINA).set(CODE).build();
    MonetaryAmountFormat format = MonetaryFormats.getAmountFormat(formatQuery);
    assertMoneyParse(format, "CNY00000123", 123.0, "CNY");
    assertMoneyParse(format, "CNY123.01", 123.01, "CNY");
    assertMoneyParse(format, "CNY14,000.12", 14000.12, "CNY");
    assertMoneyParse(format, "CNY 14,000.12", 14000.12, "CNY");
    assertMoneyParse(format, "CNY\u00A014,000.12", 14000.12, "CNY");
}
Also used : AmountFormatQuery(javax.money.format.AmountFormatQuery) MonetaryAmountFormat(javax.money.format.MonetaryAmountFormat) Test(org.testng.annotations.Test)

Example 22 with AmountFormatQuery

use of javax.money.format.AmountFormatQuery in project jsr354-ri by JavaMoney.

the class MonetaryFormatsTest method testFormat_CNY_zh_CN.

@Test
public void testFormat_CNY_zh_CN() {
    AmountFormatQuery formatQuery = AmountFormatQueryBuilder.of(CHINA).set(CODE).build();
    MonetaryAmountFormat format = MonetaryFormats.getAmountFormat(formatQuery);
    assertMoneyFormat(format, Money.of(123.01, "CNY"), "CNY123.01");
    assertMoneyFormat(format, Money.of(14000.12, "CNY"), "CNY14,000.12");
}
Also used : AmountFormatQuery(javax.money.format.AmountFormatQuery) MonetaryAmountFormat(javax.money.format.MonetaryAmountFormat) Test(org.testng.annotations.Test)

Example 23 with AmountFormatQuery

use of javax.money.format.AmountFormatQuery in project jsr354-ri by JavaMoney.

the class MonetaryAmountFormatTest method testFormatWithBuilder.

/**
 * Test method for
 * {@link javax.money.format.MonetaryAmountFormat#format(javax.money.MonetaryAmount)} .
 */
@Test
public void testFormatWithBuilder() {
    AmountFormatQuery formatQuery = AmountFormatQueryBuilder.of(JAPANESE).build();
    MonetaryAmountFormat defaultFormat = MonetaryFormats.getAmountFormat(formatQuery);
    MonetaryAmount amountChf = Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(12.50).create();
    assertEquals("CHF12.50", defaultFormat.format(amountChf));
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) AmountFormatQuery(javax.money.format.AmountFormatQuery) MonetaryAmountFormat(javax.money.format.MonetaryAmountFormat) Test(org.testng.annotations.Test)

Example 24 with AmountFormatQuery

use of javax.money.format.AmountFormatQuery in project bookJava11eDeitel by diodoros87.

the class SimpleCurrencyConverterView method getMonetaryAmountFormat.

private static MonetaryAmountFormat getMonetaryAmountFormat() {
    AmountFormatQueryBuilder builder = AmountFormatQueryBuilder.of(LOCALE_FORMAT);
    builder.set(SYMBOL);
    builder.set(PATTERN, " ยค,##0.00");
    AmountFormatQuery query = builder.build();
    MonetaryAmountFormat monetaryAmountFormat = MonetaryFormats.getAmountFormat(query);
    return monetaryAmountFormat;
}
Also used : AmountFormatQueryBuilder(javax.money.format.AmountFormatQueryBuilder) AmountFormatQuery(javax.money.format.AmountFormatQuery) MonetaryAmountFormat(javax.money.format.MonetaryAmountFormat)

Aggregations

AmountFormatQuery (javax.money.format.AmountFormatQuery)24 MonetaryAmountFormat (javax.money.format.MonetaryAmountFormat)24 Test (org.testng.annotations.Test)23 MonetaryAmount (javax.money.MonetaryAmount)3 CurrencyUnit (javax.money.CurrencyUnit)1 AmountFormatQueryBuilder (javax.money.format.AmountFormatQueryBuilder)1 MonetaryParseException (javax.money.format.MonetaryParseException)1 Ignore (org.testng.annotations.Ignore)1