当前位置:网站首页>How can we truncate the float64 type to a specific precision- How can we truncate float64 type to a particular precision?

How can we truncate the float64 type to a specific precision- How can we truncate float64 type to a particular precision?

2022-07-05 02:57:00 Technology feast

problem :

package mainimport (    "fmt"    "strconv"    )func main() {    k := 10/3.0    i := fmt.Sprintf("%.2f", k)    f,_ := strconv.ParseFloat(i, 2)    fmt.Println(f)}

I had to write the program above to decrease the precision of a go float64 variable to 2. In this case I was using both strconv and fmt. I have to write the above program to go float64 The accuracy of the variable is reduced to 2. under these circumstances , I used... At the same time strconv and fmt.Is there some other logical method by which it can be done? Is there any other logical method to complete ?


Solution :

Reference resources : https://stackoom.com/en/question/1FA9C
原网站

版权声明
本文为[Technology feast]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140835482377.html