How to convert float to string with 2 decimal places in Go

1 Answer

0 votes
package main

import "fmt"

func main() {
	f := 787324.9761

	s := fmt.Sprintf("%.2f", f)

	fmt.Println(s)
}

/*
run:

787324.98

*/

 



answered Feb 12, 2023 by avibootz
edited Feb 12, 2023 by avibootz

Related questions

1 answer 110 views
1 answer 204 views
2 answers 237 views
2 answers 205 views
2 answers 259 views
1 answer 209 views
...