Significant digits in a float?
Roy Smith
roy at panix.com
Mon Apr 28 14:39:30 EDT 2014
On Monday, April 28, 2014 12:07:14 PM UTC-4, Ned Batchelder wrote:
> On 4/28/14 12:00 PM, Roy Smith wrote:
>> 38.0 ==> 0
>> [...]
>> Is there any clean way to do that? The best I've come up with so far is to str() them and parse the
>> remaining string to see how many digits it put after the decimal point.
>
> That sounds like a pretty clean way: len(str(num).partition(".")[2]),
> though it also sounds like you understand all of the inaccuracies in
Well, it's actually, a little uglier, because I want to map 38.0 ==>0, so I need to special case that.
The other annoying thing about using str() is its behavior isn't well defined. It looks like it does the right thing, but I imagine the details could change in a different implementation.
More information about the Python-list
mailing list