Browse Source

Merge pull request #1255 from kyuupichan/amountedit2

Fix nasty bug in amount editors
283
ThomasV 10 years ago
parent
commit
8e6e4f1b92
  1. 8
      gui/qt/amountedit.py
  2. 11
      lib/util.py

8
gui/qt/amountedit.py

@ -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()))

11
lib/util.py

@ -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)

Loading…
Cancel
Save