Task: add computeFromBaseRate function in money-modules
This commit is contained in:
parent
c4e7f514cb
commit
aaf3c6aea8
@ -14,4 +14,23 @@ object MoneyExchangeUtils {
|
||||
fun getBaseCurrency(): StdMoney.Currency {
|
||||
return StdMoney.USD
|
||||
}
|
||||
|
||||
/**
|
||||
* Compute the Base Exchange Price / Converter to any Rates.
|
||||
* Multiple differentiate exchange relation computation.
|
||||
* Example: A -> B -> C meant You can with all variables, but must find the based MEANT of its.
|
||||
*
|
||||
* Sample Explanation: Matrix Multiply
|
||||
* 1 USD -> 0.90 EUR
|
||||
* 1 USD -> 4000 KHR
|
||||
* If I want to exchange from EUR to KHR, I need.
|
||||
* 1 EUR -> 1 * (1 / 0.90) / (1 / 4000)
|
||||
*
|
||||
* @author sombochea
|
||||
* @since 1.0
|
||||
*/
|
||||
fun computeFromBaseRate(amountFrom: Double = 1.0, baseRate: Double = 1.0, rateFrom: Double, rateTo: Double): Double {
|
||||
// amount * ((baseRate / rateFrom) / (baseRate / rateTo))
|
||||
return amountFrom.times((baseRate.div(rateFrom)).div(baseRate.div(rateTo)))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user