diff --git a/src/main/kotlin/com/cubetiqs/money/MoneyExchangeUtils.kt b/src/main/kotlin/com/cubetiqs/money/MoneyExchangeUtils.kt index 19a7ceb..c869938 100644 --- a/src/main/kotlin/com/cubetiqs/money/MoneyExchangeUtils.kt +++ b/src/main/kotlin/com/cubetiqs/money/MoneyExchangeUtils.kt @@ -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))) + } } \ No newline at end of file