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 219 views
1 answer 322 views
2 answers 382 views
2 answers 377 views
2 answers 420 views
1 answer 316 views
...