paulmach / orb

Types and utilities for working with 2d geometry in Golang
MIT License
886 stars 103 forks source link

How to update DefaultRoundingFactor for Lat/Lon? #125

Closed arif2009 closed 8 months ago

arif2009 commented 1 year ago

I need Lat()/Lon() up to 8 decimal places, but it always returns 6 decimal places. How can I upgrade it to 8?

paulmach commented 1 year ago

those are numbers (i.e float64) so it's all about how you display

fmt.Printf("%v\n", math.Pi)
fmt.Printf("%f\n", math.Pi)
fmt.Printf("%.8f\n", math.Pi)

returns

3.141592653589793
3.141593
3.14159265

https://play.golang.com/p/Tai8YwZvR0V

arif2009 commented 1 year ago

@paulmach It is not working because here https://github.com/paulmach/orb/blob/v0.9.0/define.go#L8 it restrict upto 6 decimal places

paulmach commented 1 year ago

that's DefaultRoundingFactor used for rounding. And you can change it

Can you provide some more context on "always returns 6 decimal places". What returns only 6?

arif2009 commented 1 year ago

My code is like this:

m := minGeomScan.Geometry.(orb.Point)
ml := jsonschema.LatLon{
    Lng: m.Lon(),
    Lat: m.Lat(),
}

where m.Lon() & m.Lat() always returns up to 6 decimal places, but I need it to make 8.

paulmach commented 1 year ago

m.Lat() and m.Lng() do not return 6 decimal places. They return a float64.

This is related to you're input, how you're parsing data to create the minGeomScan or your output, how you can see the 6 decimal places.

arif2009 commented 1 year ago

how you can see the 6 decimal places.

I see it from O/P data, sometimes it returns 4 or 5 decimal places but it doesn't go upto 6 decimal places even I use your example like fmt.Printf("%.8f\n", m.Lon()). It shows 00 after the 6th for %.8f.