how do I convert this code (javascript code) into solidity code and it will work?
function pmt(rate_per_period, number_of_payments, present_value, future_value){
if(rate_per_period != 0.0){
// Interest rate exists
var q = Math.pow(1 + rate_per_period, number_of_payments);
return (rate_per_period * (future_value + (q * present_value))) / ((q-1) * (1 + rate_per_period ));
} else if(number_of_payments != 0.0){
// No interest rate, but number of payments exists
return -(future_value + present_value) / number_of_payments;
}
return 0;}
already did this function :
function PMT(uint _rate,uint256 _term,uint _pv) public view returns (uint)
{
uint q = ((1 + _rate) ** _term);
return (_rate * (((1 + _rate) ** _term) * _pv)) / ((((1 + _rate) ** _term)-1) * (1+_rate));
}
and, how do I represent the decimal value in solidity? Fixed point numbers are not fully supported by Solidity yet. They can be declared, but cannot be assigned to or from.
for example the function parameters:
pmt(0.0025,12,700000);
*************EDIT
multiply function wont work
the arguments of the PMT :
- totalFunding (700000)
- totalMonths (12)
- totalYears(1)
- annualYieldInterest(3% - 0.03)
if i will power them via 10 ** 2 = 100 the parameters will be:
- totalFunding (70000000)
- totalMonths (1200)
- totalYears(100)
- annualYieldInterest(3% - 0.03 - 3)
before I start to calculate PMT function I have to calculate the parameters he gets:
- totalFunding : 70000000
- rate:3/1200 - 0.0025 (via the parameters above)
- totalMonths:12
so still I get float value.