# flota64后面保留三位小数

1、需要转成字符串形式的：

fmt.Sprintf("%.3f", 1.23456)

strconv.ParseFloat(fmt.Sprintf("%.3f",v), 3)

2、不需要转成字符串形式的：

value = math.Trunc(value\**1e3 + 0.5)\**&#x31;e-3

加上 0.5是为了四舍五入，想保留几位小数的话把3改掉即可

封装成函数

```
func Round(f float64, n int) float64 {
    pow10_n := math.Pow10(n)
    return math.Trunc((f+0.5/pow10_n)*pow10_n) / pow10_n
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://zhounanjun.gitbook.io/nanjun/golang/flota64-hou-mian-bao-liu-san-wei-xiao-shu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
