Configurable significance for numbers in java's String.format()? -
i'm tasked writing function format set (coordinate) of doubles configurable significance. have:
public string dpath(int sign) { return string.format ("%s %." + sign + "f %." + sign + "f", prefix, this.x, this.y); }
which works:
movement m = new movement(3.14159265, 2.7654321); assert.assertequals("m 3.142 2.765", m.dpath(3));
is possible without string concatenation? current implementation looks bit unnatural, may attributed unnatural use case?
just measure.
return string.format(string.format("%%s %%.%df %%.%df", sign, sign), prefix, this.x, this.y);
Comments
Post a Comment