On Thu, Sep 1, 2016, at 02:17, Greg Ewing wrote:
> 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.

If the space needs to be between the number and the unit there's no good
way to do this. I think this is an argument for a separate function that
returns a tuple of (formatted number, prefix).

Incidentally, do we have a good primitive to return (string of digits,
exponent or position of decimal point) a la C's ecvt/fcvt? This would be
something that might be useful in allowing users to build their own
formatting code. It can be worked around though ("guess" the exponent,
scale with multiplication or division, round to an integer to get the
string of digits) so I guess it's not that important.

> 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.

What I was getting at is that there are two different use cases possible
here.

> 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.

Exactly n+1, surely? And on the other hand a fixed number of decimal
places allows easy alignment by right-justifying the text within a field
(and will use at most n+4 characters for the numeric part).
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to