Skip to content

Complex expressions are not working #6

@jaydeepbhayani

Description

@jaydeepbhayani

I have an expression like this -> "(0.341 * 8000.0) / (1 - (1 + 0.341) ^ -84)"

Expected result - "109.71908469357446"
Actual result - "1.538906384258725e-36"

calculation should be done like below snippet

fun calculateMonthlyInstallment(loanAmount: Double, monthlyInterestRate: Double, numberOfMonths: Int): Double {
    val monthlyInterestRateDecimal = monthlyInterestRate / 100.0  // Convert percentage to decimal
    val power = Math.pow(1 + monthlyInterestRateDecimal, -numberOfMonths.toDouble())
    return (monthlyInterestRateDecimal * loanAmount) / (1 - power)
}

fun main() {
    val loanAmount = 8000.0
    val monthlyInterestRate = 0.341  // 0.5% interest rate
    val numberOfMonths = 84
    val monthlyInstallment = calculateMonthlyInstallment(loanAmount, monthlyInterestRate, numberOfMonths)
    println("Monthly Installment: $monthlyInstallment")
}

Metadata

Metadata

Assignees

Labels

invalidThis doesn't seem right

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions