Golang Truncate Float To 1 Decimal Place

[Solved] Golang Truncate Float To 1 Decimal Place | Haskell - Code Explorer | yomemimo.com
Question : golang truncate float to 1 decimal place

Answered by : defiant-dove-qes2so4jpzh7

x := 12.3456
fmt.Println(math.Floor(x*100)/100) // 12.34 (round down)
fmt.Println(math.Round(x*100)/100) // 12.35 (round to nearest)
fmt.Println(math.Ceil(x*100)/100) // 12.35 (round up)

Source : https://yourbasic.org/golang/round-float-2-decimal-places/ | Last Update : Tue, 11 Jan 22

Answers related to golang truncate float to 1 decimal place

Code Explorer Popular Question For Haskell