mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-09-03 20:35:13 +00:00
Modify format_satoshis to display amounts according to locale.
In particular, thousands and decimal point separators are taken from locale.
This commit is contained in:
parent
4bed294ddd
commit
83e05b1183
2 changed files with 17 additions and 22 deletions
|
@ -20,6 +20,6 @@ class HistoryWidget(QTreeWidget):
|
||||||
if date is None:
|
if date is None:
|
||||||
date = _("Unknown")
|
date = _("Unknown")
|
||||||
item = QTreeWidgetItem([amount, address, date])
|
item = QTreeWidgetItem([amount, address, date])
|
||||||
if float(amount) < 0:
|
if amount.find('-') != -1:
|
||||||
item.setForeground(0, QBrush(QColor("#BC1E1E")))
|
item.setForeground(0, QBrush(QColor("#BC1E1E")))
|
||||||
self.insertTopLevelItem(0, item)
|
self.insertTopLevelItem(0, item)
|
||||||
|
|
37
lib/util.py
37
lib/util.py
|
@ -108,28 +108,23 @@ def user_dir():
|
||||||
|
|
||||||
|
|
||||||
def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespaces=False):
|
def format_satoshis(x, is_diff=False, num_zeros = 0, decimal_point = 8, whitespaces=False):
|
||||||
from decimal import Decimal
|
from locale import localeconv
|
||||||
if x is None:
|
if is_diff:
|
||||||
return 'unknown'
|
fmt = "{:+n}"
|
||||||
s = Decimal(x)
|
else:
|
||||||
sign, digits, exp = s.as_tuple()
|
fmt = "{:n}"
|
||||||
digits = map(str, digits)
|
scale_factor = pow (10, decimal_point)
|
||||||
while len(digits) < decimal_point + 1:
|
integer_part = fmt.format(int(x / float(scale_factor)))
|
||||||
digits.insert(0,'0')
|
dp = localeconv()['decimal_point']
|
||||||
digits.insert(-decimal_point,'.')
|
fract_part = ("{:0" + str(decimal_point) + "}").format(abs(x) % scale_factor)
|
||||||
s = ''.join(digits).rstrip('0')
|
fract_part = fract_part.rstrip('0')
|
||||||
if sign:
|
if len(fract_part) < num_zeros:
|
||||||
s = '-' + s
|
fract_part += "0" * (num_zeros - len(fract_part))
|
||||||
elif is_diff:
|
result = integer_part + dp + fract_part
|
||||||
s = "+" + s
|
|
||||||
|
|
||||||
p = s.find('.')
|
|
||||||
s += "0"*( 1 + num_zeros - ( len(s) - p ))
|
|
||||||
if whitespaces:
|
if whitespaces:
|
||||||
s += " "*( 1 + decimal_point - ( len(s) - p ))
|
result += " " * (decimal_point - len(fract_part))
|
||||||
s = " "*( 13 - decimal_point - ( p )) + s
|
result = " " * (17 - len(result)) + result
|
||||||
return s
|
return result
|
||||||
|
|
||||||
|
|
||||||
def format_time(timestamp):
|
def format_time(timestamp):
|
||||||
import datetime
|
import datetime
|
||||||
|
|
Loading…
Add table
Reference in a new issue