I am learning golang, working on time value of money computations
I am trying to compute for number of period to say, double your money. The formula that I am using is period = log(fv/pv) / log(1 + i). What I have so far is...
package main
import (
"fmt"
"math"
)
var (
interest,
futureValue,
period,
presentValue float64
)
var rate float64 = interest / 100 //converts interest into decimal... interest / 100
var ratex float64 = 1 + interest //used for (1 + i)
func main() {
numPeriod()
}
func numPeriod() {
fmt.Println("Enter interest amount: ")
fmt.Scanf("%g", &interest)
fmt.Println("Enter present value: ")
fmt.Scanf("%g", &presentValue)
fmt.Println("Enter future value: ")
fmt.Scanf("%g", &futureValue)
var logfvpvFactor float64 = futureValue / presentValue
var logi float64 = math.Log(ratex)
var logfvpv float64 = math.Log(logfvpvFactor)
period = logfvpv / logi
fmt.Printf("Number of period/s is = %g
", period)
}
Running this, I get...
Number of period/s is = +Inf
...the answer I was looking for is either an integer or a float. How do I get that?
Thanks for your help!