Answers for "golang truncate float to 1 decimal place"

Go
0

golang truncate float to 1 decimal place

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)
Posted by: Guest on January-04-2022

Code answers related to "golang truncate float to 1 decimal place"

Browse Popular Code Answers by Language