Fix nasty bug in amount editors

str() can convert amounts to scientific notation
This commit is contained in:
Neil Booth 2015-05-27 16:34:42 +09:00
parent 7becb28ec8
commit e5d243e08c
2 changed files with 9 additions and 10 deletions

View File

@ -4,6 +4,7 @@ from PyQt4.QtCore import *
from PyQt4.QtGui import *
from decimal import Decimal
from electrum.util import format_satoshis_plain
class MyLineEdit(QLineEdit):
frozen = pyqtSignal()
@ -93,8 +94,5 @@ class BTCAmountEdit(AmountEdit):
def setAmount(self, amount):
if amount is None:
self.setText("")
return
p = pow(10, self.decimal_point())
x = amount / Decimal(p)
self.setText(str(x))
else:
self.setText(format_satoshis_plain(amount, self.decimal_point()))

View File

@ -2,6 +2,7 @@ import os, sys, re, json
import platform
import shutil
from datetime import datetime
from decimal import Decimal
import urlparse
import urllib
import threading
@ -104,10 +105,11 @@ def user_dir():
#raise Exception("No home directory found in environment variables.")
return
def format_satoshis_plain(x):
'''Display a satoshi amount in BTC with 8 decimal places. Always
uses a '.' as a decimal point and has no thousands separator'''
return "{:.8f}".format(x / 100000000.0)
def format_satoshis_plain(x, decimal_point = 8):
'''Display a satoshi amount scaled. Always uses a '.' as a decimal
point and has no thousands separator'''
scale_factor = pow(10, decimal_point)
return "{:.8f}".format(Decimal(x) / scale_factor).rstrip('0').rstrip('.')
def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespaces=False):
from locale import localeconv
@ -223,7 +225,6 @@ def block_explorer_URL(config, kind, item):
def parse_URI(uri):
import bitcoin
from decimal import Decimal
if ':' not in uri:
assert bitcoin.is_address(uri)