Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You could just check that

type(x) == float

Or, instead of round, you could use python's string formatter.

"{:.5g}".format(x)

will format x using 5 digits of precision (including before and after the decimal separator), removing trailing zeroes and the decimal dot for integers. Not exactly equivalent to your code, but maybe it will be good enough for your use.

If you have a locale configured for French/Italian/whatever notation

"{:.5n}".format(x)

will automatically put a comma instead of a dot for you.