我正在学习golang,致力于计算金钱的时间价值 我试图计算一段时间来说,加倍你的钱。我正在使用的公式是period = log(fv/pv) / log(1 + i)。我到目前为止是...
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\n", period)
}
运行这个,我得到...
Number of period/s is = +Inf...我正在寻找的答案是一个整数或一个浮点数。我如何获得? 谢谢你的帮助!