so many pep8 fixes
(cherry picked from commit bee125d)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import math
|
||||
|
||||
|
||||
def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=False):
|
||||
"""
|
||||
Add suffix to value, transform value to match new suffix and round it.
|
||||
@@ -34,7 +35,7 @@ def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=Fal
|
||||
for key in posOrders:
|
||||
# Find first suitable suffix and check if it's not above highest order
|
||||
if abs(val) >= 10**key and key <= highest:
|
||||
mantissa, suffix = val/float(10**key), posSuffixMap[key]
|
||||
mantissa, suffix = val / float(10 ** key), posSuffixMap[key]
|
||||
# Do additional step to eliminate results like 999999 => 1000k
|
||||
# If we're already using our greatest order, we can't do anything useful
|
||||
if posOrders.index(key) == 0:
|
||||
@@ -53,7 +54,7 @@ def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=Fal
|
||||
# or equal to multiplier
|
||||
if roundToPrec(mantissa, prec) >= orderDiff:
|
||||
# Divide mantissa and use suffix of greater order
|
||||
mantissa, suffix = mantissa/orderDiff, posSuffixMap[prevKey]
|
||||
mantissa, suffix = mantissa / orderDiff, posSuffixMap[prevKey]
|
||||
# Otherwise consider current results as acceptable
|
||||
break
|
||||
# Take numbers between 0 and 1, and matching/below highest possible negative suffix
|
||||
@@ -67,7 +68,7 @@ def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=Fal
|
||||
nextKey = 0
|
||||
# Check if mantissa with next suffix is in range [1, 1000)
|
||||
if abs(val) < 10**(nextKey) and key >= lowest:
|
||||
mantissa, suffix = val/float(10**key), negSuffixMap[key]
|
||||
mantissa, suffix = val / float(10**key), negSuffixMap[key]
|
||||
# Do additional step to eliminate results like 0.9999 => 1000m
|
||||
# Check if the key we're potentially switching to is greater than our
|
||||
# upper boundary
|
||||
@@ -81,7 +82,7 @@ def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=Fal
|
||||
if roundToPrec(mantissa, prec) >= orderDiff:
|
||||
# Divide mantissa and use suffix of greater order
|
||||
# Use special handling of zero key as it's not on the map
|
||||
mantissa, suffix = mantissa/orderDiff, posSuffixMap[nextKey] if nextKey != 0 else ""
|
||||
mantissa, suffix = mantissa / orderDiff, posSuffixMap[nextKey] if nextKey != 0 else ""
|
||||
# Otherwise consider current results as acceptable
|
||||
break
|
||||
# Round mantissa according to our prec variable
|
||||
@@ -91,6 +92,7 @@ def formatAmount(val, prec=3, lowest=0, highest=0, currency=False, forceSign=Fal
|
||||
result = u"{0}{1}{2}".format(sign, mantissa, suffix)
|
||||
return result
|
||||
|
||||
|
||||
def roundToPrec(val, prec):
|
||||
# We're not rounding integers anyway
|
||||
# Also make sure that we do not ask to calculate logarithm of zero
|
||||
|
||||
Reference in New Issue
Block a user