当前位置:网站首页>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边栏推荐
- From task Run get return value - getting return value from task Run
- Apache build web host
- Spoon inserts and updates the Oracle database, and some prompts are inserted with errors. Assertion botch: negative time
- 看 TDengine 社区英雄线上发布会,听 TD Hero 聊开发者传奇故事
- Acwing game 58 [End]
- Problem solving: attributeerror: 'nonetype' object has no attribute 'append‘
- 【LeetCode】222. The number of nodes of a complete binary tree (2 mistakes)
- Azkaban安装部署
- 平台入驻与独立部署优缺点对比
- El tree whether leaf node or not, the drop-down button is permanent
猜你喜欢
Design and implementation of high availability website architecture
8. Commodity management - commodity classification
端口,域名,协议。
Azkaban安装部署
Problem solving: attributeerror: 'nonetype' object has no attribute 'append‘
Learn game model 3D characters, come out to find a job?
openresty ngx_lua執行階段
Design and implementation of campus epidemic prevention and control system based on SSM
Acwing第 58 场周赛【完结】
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
随机推荐
Cut! 39 year old Ali P9, saved 150million
[micro service SCG] 33 usages of filters
IPv6 experiment
PHP cli getting input from user and then dumping into variable possible?
Devtools的簡單使用
Redis distributed lock, lock code logic
The database and recharge are gone
2021 Li Hongyi machine learning (2): pytorch
The perfect car for successful people: BMW X7! Superior performance, excellent comfort and safety
Master Fur
[Yu Yue education] National Open University spring 2019 0505-22t basic nursing reference questions
Moco V2 literature research [self supervised learning]
Privatization lightweight continuous integration deployment scheme -- 01 environment configuration (Part 1)
Use UDP to send a JPEG image, and UPD will convert it into the mat format of OpenCV after receiving it
Acwing第 58 场周赛【完结】
Hmi-32- [motion mode] add light panel and basic information column
Structure of ViewModel
【LeetCode】111. Minimum depth of binary tree (2 brushes of wrong questions)
Design and implementation of campus epidemic prevention and control system based on SSM
2021 Li Hongyi machine learning (3): what if neural network training fails