Last active
December 31, 2015 14:49
-
-
Save azusa/8002755 to your computer and use it in GitHub Desktop.
計算ロジック
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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