Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@azusa
Last active December 31, 2015 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azusa/8002755 to your computer and use it in GitHub Desktop.
Save azusa/8002755 to your computer and use it in GitHub Desktop.
計算ロジック
package jp.fieldnotes.sample.singleton;
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
public class Calculator {
TaxSingleton singleton = TaxSingleton.getInstance();
/**
* 端数は四捨五入で消費税額を計算します。
* @param price 元の金額
* @return 消費税額
*/
public int calculate(int price){
return new BigDecimal(price).multiply(singleton.getRate() , MathContext.UNLIMITED).divide(new BigDecimal(100), RoundingMode.HALF_UP).intValue();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment