Each time you call format, it appends the given string, and then you append it to the StringBuffer. So after first call formatter will contain
int field: %d\n
after second call:
int field: 145
long field: 789
and so on.
So its better to use formatter as a String buffer and the just to make to string:
formatter.format("int field: %d\n", i);
formatter.format("long field: %d\n", l);
formatter.format("float field: %f\n", f);
formatter.format("double field: %f\n", d);