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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -