How to convert float to string in Go

2 Answers

0 votes
package main

import "fmt"

func main() {
	f := 804719.8361

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

	fmt.Println(s)
}


/*
run:

804719.8361

*/

 



answered Oct 30, 2024 by avibootz
0 votes
package main

import (
	"fmt"
	"strconv"
)

func main() {
	fnum := 804719.8361

	s := strconv.FormatFloat(fnum, 'f', -1, 64)

	fmt.Println(s)
}


/*
run:

804719.8361

*/

 



answered Oct 30, 2024 by avibootz

Related questions

1 answer 195 views
3 answers 238 views
238 views asked May 26, 2020 by avibootz
1 answer 113 views
1 answer 158 views
158 views asked May 26, 2020 by avibootz
1 answer 96 views
...