|| at Jan 24, 2013 at 11:34 am
Since you want fixed precision I think it's enough for you to round
x*1e6 to the nearest integer n and check n%10, n%100 etc.
Given that coordinates are bounded the probability that you obtain a
wrong result doing so is extremely thin.
If you want to do it properly, the algorithm is equivalent to using
strconv.AppendFloat and it's already quite efficient.
2013/1/24, Johann Höchtl <firstname.lastname@example.org
On 23.01.2013 16:10, Russ Cox wrote:
On Wed, Jan 23, 2013 at 3:36 AM, Johann Höchtl
This question is only mildly Go - related.
Is there a more efficient way to determine the places after comma
(remainder) of a float64 rather than converting to string and
determining the length of the remainer? I currently perform a
round to six places and afterwards perform a
fmt.Sprintf("%.*f", prec, val) but that seems highly inefficient.
I am aware that there are numbers for which there is no exact Base2
--> Base10 conversion.
I am not sure what you are asking. The answer is probably no, but can
you give an example?
I want to determine the "places" of a float reminder for the required
precision for geohash encoding. 23.4 takes less space than 23.0005 or
23.4 --> 1 place
23.0005 -> 4 places
23.123456 --> 6 places
The most straight-forward way (for me) is to convert to string
fmt.Sprintf("%.*f", prec, val) but I am pretty sure there is a more