GNOME Bugzilla – Bug 95844
QIF Import -denom set for integer misinterpreted by numeric_convert
Last modified: 2018-06-29 20:19:26 UTC
In the Q field of QIF file, when a positive entry contains no decimal point, the double_to_gnc_numeric function in gnc-numeric.c returns both a negative numerator and negative denominator. However, the gnc_numeric_convert interprets a negative denominator as signifying multiply instead of divide. This results in incorrect values. For example, Q6,666 results in :out.num=-66660 :out.denom=-10 on output from double_to_gnc_numeric. However, when these values are passed to gnc_numeric_convert, with how=7, the output is: :out.num=66660000000 :out.denom=100000 which give a value of 666600 instead of 6666 as required.
The problem is caused by: (gnc:double-to-gnc-numeric (+ 0.0 read-val) GNC-DENOM-AUTO (logior (GNC-DENOM-SIGFIGS (- (string-length filtered-string) 1)) GNC-RND-ROUND)) in the body of: (define (qif-parse:parse-number/format value-string format) the 1 is supposed to subtract for the decimal point; however, this doesn't account for this being absent in the case of an integer, e.g. 6,666. I tested a change to solve this problem; however, I got another error while reading dates: Gtk-CRITICAL **: file gtkcombo.c: line 849 (gtk_combo_set_popdown_strings): assertion `strings != NULL' failed.
The aforementioned error in file gtkcombo.c: line 849 is probably caused by the call at druid-qif-import.c:496. The format list is null. Judging from display's during the parse, all dates were parsed successfully; so, it must be something besides that. This is supported by the comments shortly before line 496.
The ultimate cause of the gtkcombo.c: line 849 error was not changing the comma radix case like the decimal radix case was changed in qif-parse:parse-number/format. After this change was made, the error disappeared. The relevant code is: (case format ((decimal) (let* ((filtered-string (string-remove-char (string-remove-char value-string #\,) #\$) );;end filtered-string (read-val (with-input-from-string filtered-string (lambda () (read))) );;end read-val (has-radix ( if (regexp-exec (make-regexp "^.*[.].*$") filtered-string) 1 0 ) );;end has-radix );;end let* (if (number? read-val) (begin (gnc:double-to-gnc-numeric (+ 0.0 read-val) GNC-DENOM-AUTO (logior (GNC-DENOM-SIGFIGS (- (string-length filtered-string) has-radix)) GNC-RND-ROUND)) );;end begin for then part of if (gnc:numeric-zero);;end else part of if );;end if );;end let* );;end decimal case
A (different) patch for this problem has been committed to CVS.
from Larry: I just tested it and it worked fine. So I'm closing this as fixed. Thanks!
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=95844. Please update any external references or bookmarks.