* Dante Castagnoli <dante.castagn...@gmail.com> [221010 18:01]:
> Thanks!
> 
> It's not lost, though.  It shows up with the %g form.
> 
> Knowing about %g, my issue is not extant, but others might hit it.  I'm 
> relatively new to floating point issues, and I saw numbers showing up as 
> integers, and it took a while to sort out what was going on, is all.
> 
> As the behavior matches "c", I would suggest at minimum making the 
> documentation clearer.
> 
> https://go.dev/play/p/WBlf3jltimr

Your comparison is flawed.  Take your original playground code (the one
with just %0.3f) and change the "f" to "g" without removing the "0.3"
and run it again.  You will see the same rounding behavior as with "f".

The documentation says:

  The default precision ... for %g ... is the smallest number of digits
  necessary to identify the value uniquely.

So without explicitly specifying the precision, %g will print as many
digits as necessary (i.e. enough precision is used to prevent rounding).

What representation, using only the precision specified, most closely
represents the value being formatted?  That is how you should think of
the floating point formatting behavior, rather than thinking of it as
rounding.

...Marvin

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/Y0VX94m6RoYs5X8i%40basil.wdw.

Reply via email to