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)
1.4m articles
1.4m replys
5 comments
56.9k users