fsharp复合兴趣初学者

时间:2015-03-28 19:54:31

标签: f#

我不知道我应该在这里做什么我是初学者

let interest = 0.02     // Interest rate is 2%

let periods = 12.0      // Number of times the interest is compounded per year

let years = 10.0        // Number of years the money is borrowed for


// Calculate compound interest using the formula from:
// http://en.wikipedia.org/wiki/Compound_interest#Compound_Interest

let compound investment = 
    ***I am supposed to put something here***

let res = compound 1000.0

shouldEqual (round res) 1221.0

printfn "Compound interest (full): %f" res

printfn "Compound interest (two digits): %.2f" res

1 个答案:

答案 0 :(得分:1)

如果你理解的话:

let interest = 0.02     // Interest rate is 2%
let periods = 12.0      // Number of times the interest is compounded per year
let years = 10.0        // Number of years the money is borrowed for
let investment = 1000.0     //principal amount (initial investment)

// Calculate compound interest using the formula from:
// http://en.wikipedia.org/wiki/Compound_interest#Compound_Interest
let compound P j n t = 
    P*((1.0+j/n)**(n*t))

let res = compound investment interest periods years

//shouldEqual (round res) 1221.0 ? What this?

printfn "Compound interest (full): %f" res
printfn "Compound interest (two digits): %.2f" res

但我很惊讶我在这里看到了这个问题