commit
d2bf875b8e
2 changed files with 9 additions and 5 deletions
|
|
@ -80,8 +80,8 @@ class TestFmtMoney(unittest.TestCase):
|
|||
self.assertEqual(fmt_money(100000.1234), "100,000.1234")
|
||||
self.assertEqual(fmt_money(1000000.3456), "1,000,000.3456")
|
||||
self.assertEqual(fmt_money(10000000.3344567), "10,000,000.3345")
|
||||
self.assertEqual(fmt_money(100000000.37827268), "100,000,000.378")
|
||||
self.assertEqual(fmt_money(1000000000.2718272637), "1,000,000,000.27")
|
||||
self.assertEqual(fmt_money(100000000.37827268), "100,000,000.3783")
|
||||
self.assertEqual(fmt_money(1000000000.2718272637), "1,000,000,000.2718")
|
||||
frappe.db.set_default("currency_precision", "")
|
||||
|
||||
if __name__=="__main__":
|
||||
|
|
|
|||
|
|
@ -373,8 +373,10 @@ def fmt_money(amount, precision=None, currency=None):
|
|||
# 40,000.23000 -> 40,000.23
|
||||
|
||||
if decimal_str:
|
||||
parts = str(amount).split(decimal_str)
|
||||
decimals = parts[1] if len(parts) > 1 else ''
|
||||
decimals_after = str(round(amount % 1, precision))
|
||||
parts = decimals_after.split(decimal_str)
|
||||
parts = parts[1] if len(parts) > 1 else ''
|
||||
decimals = parts
|
||||
if precision > 2:
|
||||
if len(decimals) < 3:
|
||||
if currency:
|
||||
|
|
@ -386,6 +388,7 @@ def fmt_money(amount, precision=None, currency=None):
|
|||
precision = len(decimals)
|
||||
|
||||
amount = '%.*f' % (precision, round(flt(amount), precision))
|
||||
|
||||
if amount.find('.') == -1:
|
||||
decimals = ''
|
||||
else:
|
||||
|
|
@ -413,7 +416,8 @@ def fmt_money(amount, precision=None, currency=None):
|
|||
parts.reverse()
|
||||
|
||||
amount = comma_str.join(parts) + ((precision and decimal_str) and (decimal_str + decimals) or "")
|
||||
amount = minus + amount
|
||||
if amount != '0':
|
||||
amount = minus + amount
|
||||
|
||||
if currency and frappe.defaults.get_global_default("hide_currency_symbol") != "Yes":
|
||||
symbol = frappe.db.get_value("Currency", currency, "symbol") or currency
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue