Giter VIP home page Giter VIP logo

java-money-utils's Introduction

#java-money-utils

精确的单位运算

Library that is designed to simplify tasks that involve a subject of money. It consists of a few classes:

  • Money is a Currency and BigDecimal pair which holds an amount of money.
  • ExchangeRates is a map of available exchange rates from one currency to another.
  • CurrencyUtils provides a functionality of converting between ISO4217 alpha and numeric codes.

###Examples:

//Adding RUB to USD to get result in RUB
Money roubles = new Money(Currency.getInstance("RUB"), new BigDecimal(100)); // 100.00 RUB
Money dollars = new Money(Currency.getInstance("USD"), new BigDecimal(10.5d)); // 10.50 USD

ExchangeRates exchangeRates = new ExchangeRates();
exchangeRates.putRate(Currency.getInstance("USD"), Currency.getInstance("RUB"), new BigDecimal(35.15)); // Adding an exchange rate from USD to RUB so that 1 USD == 35.15 RUB

Money sum = Money.addition(Currency.getInstance("RUB"), exchangeRates, roubles, dollars); // 469.08 RUB
//Currencies from ISO4217 number form
Money moneyUSD = new Money(CurrencyUtils.getCurrencyForNumericCode(840), new BigDecimal(100)); // 100.00 USD 
Money moneyRUB = new Money(CurrencyUtils.getCurrencyForNumericCode(643), new BigDecimal(1488)); // 1488.00 RUB
Money moneyEUR = new Money(CurrencyUtils.getCurrencyForNumericCode(978), new BigDecimal(666.69d)); // 666.69 EUR
//Rounding and empty currency
Money money = new Money(CurrencyUtils.getCurrencyForAlphaCode("XXX"), new BigDecimal(1000000)); // 1000000.00 XXX - empty currency

Money moneyRoundingModeUP = Money.division(money, new BigDecimal(3), 6, RoundingMode.UP); // 333333.33 XXX
BigDecimal underlyingAmount = moneyRoundingModeUP.getSum(); // 333333.333334

java-money-utils's People

Contributors

liyuanmingabc avatar thenixan avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.