I am pretty formatting a floating point number but want it to appear as an integer if there is no relevant floating point number.
I.e.
I can achieve this with a bit of regex but wondering if there is a sprintf-only way of doing this?
sprintf
I am doing it rather lazily in ruby like so:
("%0.2fx" % (factor / 100.0)).gsub(/.?0+x$/,'x')
You want to use %g instead of %f:
%g
%f
"%gx" % (factor / 100.00)
2.1m questions
2.1m answers
60 comments
57.0k users