本文整理汇总了Java中org.javamoney.moneta.FastMoney类的典型用法代码示例。如果您正苦于以下问题:Java FastMoney类的具体用法?Java FastMoney怎么用?Java FastMoney使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FastMoney类属于org.javamoney.moneta包,在下文中一共展示了FastMoney类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: act
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Override
public Response act(Request req) throws IOException {
try {
long number = Long.parseLong(((RqRegex) req).matcher().group("number"));
Product product = base.products().product(number);
JsonReader reader = Json.createReader(req.body());
JsonObject json = reader.readObject();
String name = json.getString("name");
String desc = json.getString("desc");
FastMoney price = FastMoney.of(new BigDecimal(json.getString("price")), "CZK");
Product result = product.update(name, desc, price);
return new RsJson(result);
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
示例2: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit currency = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, currency);
MonetaryOperator doubleOperator = m -> m.multiply(2);
MonetaryAmount result = doubleOperator.apply(money);//BRL 20.00000
MonetaryAmount result2 = result.with(doubleOperator);//BRL 40.00000
}
示例3: setupModule
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Override
public void setupModule(final SetupContext context) {
final SimpleSerializers serializers = new SimpleSerializers();
serializers.addSerializer(CurrencyUnit.class, new CurrencyUnitSerializer());
serializers.addSerializer(MonetaryAmount.class, new MonetaryAmountSerializer(names, writer, formatFactory));
context.addSerializers(serializers);
final SimpleDeserializers deserializers = new SimpleDeserializers();
deserializers.addDeserializer(CurrencyUnit.class, new CurrencyUnitDeserializer());
deserializers.addDeserializer(MonetaryAmount.class, new MonetaryAmountDeserializer<>(amountFactory, names));
// for reading into concrete implementation types
deserializers.addDeserializer(Money.class, new MonetaryAmountDeserializer<>(moneyFactory, names));
deserializers.addDeserializer(FastMoney.class, new MonetaryAmountDeserializer<>(fastMoneyFactory, names));
deserializers.addDeserializer(RoundedMoney.class, new MonetaryAmountDeserializer<>(roundedMoneyFactory, names));
context.addDeserializers(deserializers);
}
示例4: otherOperations
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Test
public void otherOperations() {
CurrencyUnit euro = Monetary.getCurrency("EUR");
MonetaryAmount amount = FastMoney.of(150, euro);
FastMoney money = FastMoney.of(150, "EUR");
assertEquals(amount, money);
FastMoney third = money.divide(3);
assertEquals(third, FastMoney.of(50, euro));
MonetaryOperator tenPercent = MonetaryOperators.percent(10);
FastMoney tenPercentValue = money.with(tenPercent);
assertEquals(tenPercentValue, FastMoney.of(15, "EUR"));
// excellent comparison functions:
//money.isZero()
//MonetaryFunctions
Log.d("test", "the end, debug manually");
}
示例5: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
/**
* @param args
*/
public static void main(String[] args) {
MonetaryAmount amount = Monetary.getDefaultAmountFactory().setCurrency("EUR").setNumber(234).create();
ConsoleUtils.printDetails(amount);
amount = Monetary.getAmountFactory(FastMoney.class).setCurrency("EUR").setNumber(234).create();
ConsoleUtils.printDetails(amount);
amount = Monetary.getAmountFactory(
MonetaryAmountFactoryQueryBuilder.of().setMaxScale(50).setPrecision(30).build())
.setCurrency("EUR").setNumber(234).create();
ConsoleUtils.printDetails(amount);
Money amt1 = Money.of(10.1234556123456789, "USD");
FastMoney amt2 = FastMoney.of(123456789, "USD");
Money total = amt1.add(amt2).multiply(0.5)
.remainder(1);
ConsoleUtils.printDetails(total);
}
示例6: setAmount
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public void setAmount(MonetaryAmount amount) {
if (amount != null) {
codeBox.getSelectionModel().select(
amount.getCurrency().getCurrencyCode());
if (FastMoney.class.equals(amount.getClass())) {
numberType.getSelectionModel().select("Long");
} else {
numberType.getSelectionModel().select("BigDecimal");
}
numberValue.setText(Money.from(amount).getNumber()
.toString());
} else {
codeBox.getSelectionModel().clearSelection();
numberType.getSelectionModel().clearSelection();
numberValue.setText("0");
}
}
示例7: act
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Override
public Response act(Request req) throws IOException {
try {
JsonReader reader = Json.createReader(req.body());
JsonObject json = reader.readObject();
String name = json.getString("name");
String desc = json.getString("desc");
MonetaryAmount price = FastMoney.of(new BigDecimal(json.getString("price")), "CZK");
Product result = base.products().add(name, desc, price);
return new RsJson(result);
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
示例8: create
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
private Product create(ResultSet rSet) throws SQLException {
return new ConstProduct(
new H2Product(dBase, rSet.getLong(1)),
rSet.getString(2),
rSet.getString(3),
FastMoney.of(rSet.getLong(4), "CZK"));
}
示例9: price
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
private MonetaryAmount price() {
try {
return FastMoney.of(
new BigDecimal(
new JdbcSession(dBase)
.sql("SELECT price FROM product WHERE id=?")
.set(this.number)
.select(new SingleOutcome<>(String.class))),
"CZK");
} catch (SQLException e) {
return ExceptionUtils.rethrow(e);
}
}
示例10: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit currency = Monetary.getCurrency("BRL");
MonetaryAmount money = Money.of(BigDecimal.TEN, currency);
MonetaryAmount money2 = FastMoney.of(BigDecimal.TEN, currency);
MonetaryAmount addResult = money.add(money2);//BRL 20 Money implementation
MonetaryAmount subtractResult = money2.subtract(addResult);//BRL -10 FastMoney implementation
}
示例11: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit currency = Monetary.getCurrency(Locale.US);
MonetaryAmount money = Money.of(10, currency);
MonetaryAmount money2 = FastMoney.of(20, currency);
MonetaryAmount money3 = RoundedMoney.of(30, currency, MonetaryOperators.rounding());
String text = money.toString();//USD 10
String text2 = money2.toString();//USD 20
String text3 = money3.toString();//USD 30
MonetaryAmount result = Money.parse(text);
MonetaryAmount result2 = FastMoney.parse(text2);
MonetaryAmount result3 = RoundedMoney.parse(text3);
}
示例12: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit currency = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, currency);
MonetaryQuery<String> currencyCodeQuery = m -> m.getCurrency().getCurrencyCode();
String result = currencyCodeQuery.queryFrom(money);//BRL
String result2 = money.query(currencyCodeQuery);//BRL
}
示例13: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, dollar);
MonetaryAmount money2 = FastMoney.of(10, real);
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.ECB);
CurrencyConversion currencyConversion = provider.getCurrencyConversion(dollar);
MonetaryAmount result = currencyConversion.apply(money2);
MonetaryAmount monetaryAmount = money.add(result);
}
示例14: main
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, dollar);
MonetaryAmount money2 = FastMoney.of(10, real);
MonetaryAmount result = money.add(money2);//javax.money.MonetaryException: Currency mismatch: USD/BRL
}
示例15: data
import org.javamoney.moneta.FastMoney; //导入依赖的package包/类
@Parameters(name = "{0}, {1}")
public static Iterable<Object[]> data() {
return Arrays.asList(new Object[][]{
{FastMoney.of(29.95, "EUR"), FastMoney.of(100, "EUR"), FastMoney.of(0.0001, "EUR")},
{Money.of(29.95, "EUR"), Money.of(100, "EUR"), Money.of(0.0001, "EUR")},
{RoundedMoney.of(29.95, "EUR", getDefaultRounding()),
RoundedMoney.of(100, "EUR", getDefaultRounding()),
RoundedMoney.of(0.0001, "EUR", getDefaultRounding())},
});
}