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 108 views
1 answer 203 views
2 answers 234 views
2 answers 202 views
2 answers 256 views
1 answer 207 views
...