duandanai6470
2018-12-21 15:05
浏览 78
已采纳

fmt.Println不会打印整个浮点数

i'm trying to make a program that calculates the value of pi and print it on the terminal, but only part of it shows on the screen

package main

import (
    "fmt"
)

func gregorypi() float64 {
    numerator := 1.0
    divisor := 3.0
    var result float64

    for i := 0; i <= 100000000; i++ {
            if i%2 == 0 {
                    result += numerator / divisor
                    divisor += 2
            } else {
                    result -= numerator / divisor
                    divisor += 2

            }

    }

    return (4 * (1 - result))

}

func main() {

    fmt.Sprint(gregorypi())

}

the output is: 3.1415926435897683

How do i make so the entire value appears?

If it helps answering the question: the formula that i'm using is the Gregory-Leibniz one

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题