Hi,

I'm wondering what folks think about the behavior of %f and precision.

The go fmt documentation states:
> For floating-point values, width sets the minimum width of the field and 
precision sets the number of places after the decimal, 

What I discovered is there is rounding going on in %f as shown below.

https://go.dev/play/p/23AfRtwOqcD

I found this behavior as I'm converting floats to integers, and was testing 
fine regions between digits, and experienced the behavior.   I didn't 
expect it.

I expected the behavior of printing "n" characters of a string.  However, I 
note that "c" behaves the same way:

$ cat math.c
#include<stdio.h>
int main(int argc, char *argv[]) {
        printf("%0.3f\n", 0.9999999999);
}
$ ./math
1.000
$ 

-- 
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/732843d6-2a65-4bed-b199-8b0260a1e82bn%40googlegroups.com.

Reply via email to