Random832 wrote:
One thing to consider is that this is very likely to be used with a unit (e.g. "%hA" intending to display in amperes), so maybe it should put a space after it? Though really people are probably going to want "1 A" vs "1 kA" in that case, rather than "1 A" vs "1kA".
I don't think a space should be automatic. The typographical recommendation is to put a thin non-breaking space between the value and the unit, but this is not possible with a monospaced font, so some people might decide that it's better without a space, or they might want to use a character other than 0x20. Better to let the user put the space in the format string if wanted.
Engineering or SI-scale-factor format suggests a third possibility: number of decimal places to be shown after the displayed decimal point, e.g. "%.1h" % 1.2345 * 10 ** x for x in range(10): "1.2", "12.3", "123.5", "1.2k", "12.3k", "123.5k", "1.2M", "12.3M", "123.5M".
I'm inclined to think it should be the number of significant digits, not decimal places, to give a more consistent precision as the magnitude of the number changes. For example, if you're displaying some resistor values that are accurate to 2 digits, you would want to see 2.7k, 27k, 270k, but not 27.0k or 270.0k as those would suggest spurious precision. This would also help with fitting the value into a fixed width, since you would know that a precision of n would use at most n+1 characters for the numeric part. -- Greg