本文整理汇总了Java中javax.money.format.MonetaryAmountFormat.format方法的典型用法代码示例。如果您正苦于以下问题:Java MonetaryAmountFormat.format方法的具体用法?Java MonetaryAmountFormat.format怎么用?Java MonetaryAmountFormat.format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.money.format.MonetaryAmountFormat
的用法示例。
在下文中一共展示了MonetaryAmountFormat.format方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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
}
示例2: 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);
}
示例3: 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
示例4: 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
示例5: 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);
}
示例6: main
import javax.money.format.MonetaryAmountFormat; //导入方法依赖的package包/类
public static void main(String[] args) {
CurrencyUnit currency = Monetary.getCurrency("BRL");
MonetaryAmount money = Money.of(12, currency);
MonetaryAmountFormat formater = MonetaryAmountDecimalFormatBuilder.of(new Locale("pt", "BR")).
withCurrencyUnit(currency).withProducer(new MoneyProducer()).build();
String format = formater.format(money);//R$ 12,00
MonetaryAmount moneyParsed = Money.parse(format, formater);//or using defafult.parse(format);
}
开发者ID:otaviojava,项目名称:money-api-book-samples,代码行数:13,代码来源:MonetaryAmountDecimalFormatBuilderExample2.java
示例7: main
import javax.money.format.MonetaryAmountFormat; //导入方法依赖的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
}
示例8: formatting
import javax.money.format.MonetaryAmountFormat; //导入方法依赖的package包/类
@Test
public void formatting() {
// Given
MonetaryAmount amount = FastMoney.of(3162.24523, "EUR");
MonetaryAmountFormat format = MonetaryFormats.getAmountFormat(Locale.GERMANY);
// When
String actual = format.format(amount);
// Then
assertEquals(actual, "3.162,25 EUR");
}