Floating point "g" format not stripping trailing zeros

Mark Lawrence breamoreboy at yahoo.co.uk
Fri Feb 13 20:22:24 EST 2015


On 14/02/2015 00:11, Ian Kelly wrote:
> On Fri, Feb 13, 2015 at 4:05 PM, Mark Lawrence <breamoreboy at yahoo.co.uk> wrote:
>> I still think it's a bug as the 'p' being referred to in the OP's original
>> message is "The precision is a decimal number indicating how many digits
>> should be displayed after the decimal point for a floating point value
>> formatted with 'f' and 'F', or before and after the decimal point for a
>> floating point value formatted with 'g' or 'G'".  In other words is has
>> nothing to do with the precision of the underlying number.
>
> I read that paragraph as describing generally what the precision
> means, with the table below detailing more specifically how it is
> used. I think for 'g' this is just trying to contrast it with 'f'
> where it really is just the number of digits displayed after the
> decimal point. The table entry for 'g' on the other hand quite clearly
> says, "for a given precision p >= 1, this rounds the number to p
> significant digits".
>

With insignificant trailing zeros removed.  So if I'm asking for 15 
significant digits *in the output* I don't expect to see those zeros as 
I don't see them as significant.  If I did I'd have p set higher.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list