[Tutor] greater precision?

Dave Angel d at davea.name
Mon Oct 29 13:00:55 CET 2012


On 10/29/2012 07:49 AM, John Collins wrote:
> Hi Dave,
>> Not true.  That's just what it was truncated to upon output.  If you
>> want to show 15 digits, then use formatted output instead of str()
>> inside the realprint() function.
> BIG light bulb moment! I had no idea the str() statement was truncating!
> I *did* search the script for "12" or "trunc" (being a newbie!) and saw
> nothing. Hence my silly questions tonight!

Not silly at all.  I didn't realize str(float) would truncate to 12
digits either.  I found out by experimenting (with 2.7) in the interpreter.

Note that it may differ from version to version.  And that's another
reason to use format.

But please don't just take the format string I supplied as "right."  It
is if you always want 15 decimal digits to the right of the decimal
point.  But if you have a number like 50 thousand, then many of those
digits to the right are invalid.



-- 

DaveA



More information about the Tutor mailing list