You need to sign in to do that
Don't have an account?
Hardik B
Error: Calculating Compound Interest on Monthly basis
Hello All,
I've a situation when calculation compound interest on monthly basis. I'm using the formula provided by the Salesforce for Compound Interest but it throws me an error. Here is the execute anon code snippet I'm trying first to figure out if I'm getting the proper output or not:
Integer mic= 50000;
Decimal int_rate= 9.5;
Integer tenure= 4;
Decimal emi= mic*(1+int_rate/12)^(tenure*12);
system.debug('Compound Interest=' +emi.round());
This is Error I'm getting: Line: 5, Column: 14
^ operator can only be applied to Boolean expressions or to Integer or Long expressions
I want to calculate montly emi so I'm using the compound interest for a specific tenure of period.
Why am I seeing this error I dont know can anyone please help me out with this ?
Help will be really appreciated.
Regards,
Hardik B.
I've a situation when calculation compound interest on monthly basis. I'm using the formula provided by the Salesforce for Compound Interest but it throws me an error. Here is the execute anon code snippet I'm trying first to figure out if I'm getting the proper output or not:
Integer mic= 50000;
Decimal int_rate= 9.5;
Integer tenure= 4;
Decimal emi= mic*(1+int_rate/12)^(tenure*12);
system.debug('Compound Interest=' +emi.round());
This is Error I'm getting: Line: 5, Column: 14
^ operator can only be applied to Boolean expressions or to Integer or Long expressions
I want to calculate montly emi so I'm using the compound interest for a specific tenure of period.
Why am I seeing this error I dont know can anyone please help me out with this ?
Help will be really appreciated.
Regards,
Hardik B.
Hi Hardik,
Please try this piece of code. Hope it will help you:
Regards,
Suraj
I tried this code in exe anon but the output is negative and as expected output. Any more tweaks need to b done ?
Hi Hardik,
Please exchange the line with.
Be careful, it is a percent rate (%) so double int_rate= 9.5/100;
The initial misunderstanding:
Formula: ^ (Exponentiation) Raises a number to a power of a specified number.
Apex: x ^ y Bitwise exclusive OR operator.
http:// https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_expressions_operators_understanding.htm (http:// https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_expressions_operators_understanding.htm)
https://help.salesforce.com/articleView?id=customize_functions.htm&type=0
Hi Hardik,
If this code helps you, Please mark it as best.Please try this piece of code. Hope it will help you: