gnucash maint: Bug 797106: Do a better job of converting decimal prices to rationals.

Mike Alexander mta at code.gnucash.org
Sat Feb 16 19:40:41 EST 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/95aed303 (commit)
	from  https://github.com/Gnucash/gnucash/commit/f22e30ba (commit)



commit 95aed303207afb37f9c0d9ac7fc13fb5f8c83e36
Author: Mike Alexander <mta at umich.edu>
Date:   Sat Feb 16 19:27:35 2019 -0500

    Bug 797106: Do a better job of converting decimal prices to rationals.
    
    Use the Scheme rationalize method to convert the decimal numbers
    from Finance::Quote to ratinal numbers.  This avoids rediculous
    precision like 8515625000000001/3906250000000000 for 2.18.

diff --git a/libgnucash/scm/price-quotes.scm b/libgnucash/scm/price-quotes.scm
index 732704f3d..d0f938ef4 100644
--- a/libgnucash/scm/price-quotes.scm
+++ b/libgnucash/scm/price-quotes.scm
@@ -404,12 +404,13 @@
               (else #f)))
 
       (if price
+          ;; The second argument to inexact->exact is chosen to give reasonable values
+          ;; for prices between .12345e-9 and 12345678.87654
+          
+          ;; inexact->exact is probably not necessary but it can't hurt and is cheap.
           (set! price
-                (double-to-gnc-numeric price
-                                       GNC-DENOM-AUTO
-                                       (logior GNC-DENOM-REDUCE
-                                               GNC-RND-NEVER))))
-
+                (gnc-scm-to-numeric 
+                  (rationalize (inexact->exact price) 1/1000000000000000))))
       (if gnc-time
           (set! gnc-time (timestr->time64 gnc-time time-zone))
           (set! gnc-time (gnc:get-today)))



Summary of changes:
 libgnucash/scm/price-quotes.scm | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)



More information about the gnucash-changes mailing list