Coordinates number format

Hey there, I got coordinates lat lng numbers which sometimes it comes like;

-00.000

And sometimes

-00.00000000000000000000000

These coordinates at the end are converted to string and shown on the screen, I need to make them always with 6 digits after the period, like;

-00.000000

For example, if it’s

-22.3275827655642464645565

I format it to

-22.327583

If it’s

-22.327 then show it like -22.327000

This var is declared as float64 and I apprecciate ante help. Tnx.

Maybe you should take a look at: https://gobyexample.com/string-formatting and:

https://medium.com/go-walkthrough/go-walkthrough-fmt-55a14bbbfc53

Format with %0.6f

https://play.golang.org/p/v7lu3MeLi1

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.