def print_json(obj):
import json
- s = json.dumps(obj,sort_keys = True, indent = 4)
+ try:
+ s = json.dumps(obj,sort_keys = True, indent = 4)
+ except TypeError:
+ s = repr(obj)
sys.stdout.write(s + "\n")
sys.stdout.flush()
return local_data
-def format_satoshis(x, is_diff=False, num_zeros = 0):
+def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespaces=False):
from decimal import Decimal
s = Decimal(x)
sign, digits, exp = s.as_tuple()
digits = map(str, digits)
- while len(digits) < 9:
+ while len(digits) < decimal_point + 1:
digits.insert(0,'0')
- digits.insert(-8,'.')
+ digits.insert(-decimal_point,'.')
s = ''.join(digits).rstrip('0')
if sign:
s = '-' + s
p = s.find('.')
s += "0"*( 1 + num_zeros - ( len(s) - p ))
- s += " "*( 9 - ( len(s) - p ))
- s = " "*( 5 - ( p )) + s
+ if whitespaces:
+ s += " "*( 1 + decimal_point - ( len(s) - p ))
+ s = " "*( 13 - decimal_point - ( p )) + s
return s