Bug 797743 - Monetary amounts are occasionally rendered in fractions

If monetary is already in decimal, don't convert. If monetary is
exact (x/y) then convert to its SCU.

As a result, monetary amounts in an arbitrary precision will be
displayed unchanged, e.g. US$0.1442, whereas exact monetary amounts
will be displayed using the currency's SCU e.g. US$1/3 -> $0.33
This commit is contained in:
Christopher Lam
2020-05-11 21:22:59 +08:00
parent 0c633866fd
commit 182d4d9de7
2 changed files with 8 additions and 4 deletions

View File

@@ -267,9 +267,13 @@
(xaccPrintAmount datum (gnc-default-print-info #f)))
(define (gnc:default-html-gnc-monetary-renderer datum params)
(xaccPrintAmount
(gnc:gnc-monetary-amount datum)
(gnc-commodity-print-info (gnc:gnc-monetary-commodity datum) #t)))
(let* ((comm (gnc:gnc-monetary-commodity datum))
(scu (gnc-commodity-get-fraction comm))
(amount (gnc:gnc-monetary-amount datum))
(amt-display (if (exact? amount)
(gnc-numeric-convert amount scu GNC-HOW-RND-ROUND)
amount)))
(xaccPrintAmount amt-display (gnc-commodity-print-info comm #t))))
(define (gnc:default-html-number-renderer datum params)
(xaccPrintAmount

View File

@@ -91,7 +91,7 @@
(set-option! options "General" "Price Source" 'weighted-average)
(let ((sxml (options->sxml portfolio-uuid options "'weighted-average")))
(test-equal "portfolio: weighted-average"
'("AAPL" "AAPL" "NASDAQ" "1.00" "$233.33" "$233 + 1/3")
'("AAPL" "AAPL" "NASDAQ" "1.00" "$233.33" "$233.33")
(sxml->table-row-col sxml 1 1 #f))))
(teardown)))