diff --git a/bindings/python/gnucash_core.py b/bindings/python/gnucash_core.py index c688097f4b..8903f7c555 100644 --- a/bindings/python/gnucash_core.py +++ b/bindings/python/gnucash_core.py @@ -49,8 +49,8 @@ from gnucash.gnucash_core_c import gncInvoiceLookup, gncInvoiceGetInvoiceFromTxn gnc_search_customer_on_id, gnc_search_bill_on_id , \ gnc_search_vendor_on_id, gncInvoiceNextID, gncCustomerNextID, \ gncVendorNextID, gncTaxTableGetTables, gnc_numeric_zero, \ - gnc_numeric_create, double_to_gnc_numeric, string_to_gnc_numeric, \ - gnc_numeric_to_string + gnc_numeric_create, double_to_gnc_numeric, gnc_numeric_from_string, \ + gnc_numeric_to_string, gnc_numeric_check from gnucash.deprecation import ( deprecated_args_session, @@ -432,8 +432,8 @@ class GncNumeric(GnuCashCoreClass): elif isinstance(arg, float): return double_to_gnc_numeric(arg, GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER) elif isinstance(arg, str): - instance = gnc_numeric_zero() - if not string_to_gnc_numeric(arg, instance): + instance = gnc_numeric_from_string(arg) + if gnc_numeric_check(instance): raise TypeError('Failed to convert to GncNumeric: ' + str(args)) return instance elif isinstance(arg, GncNumeric): diff --git a/gnucash/gnome/dialog-fincalc.c b/gnucash/gnome/dialog-fincalc.c index b6477d44ed..0b7afab19d 100644 --- a/gnucash/gnome/dialog-fincalc.c +++ b/gnucash/gnome/dialog-fincalc.c @@ -194,9 +194,8 @@ gui_to_fi (FinCalcDialog *fcd) text = gtk_entry_get_text (GTK_ENTRY(entry)); if (text && *text) { - gnc_numeric out; - gboolean result = string_to_gnc_numeric (text, &out); - if (result) + gnc_numeric out = gnc_numeric_from_string (text); + if (!gnc_numeric_check (out)) npp = gnc_numeric_convert (out, 1, GNC_HOW_RND_TRUNC); else npp = gnc_numeric_zero (); diff --git a/gnucash/import-export/log-replay/gnc-log-replay.c b/gnucash/import-export/log-replay/gnc-log-replay.c index 68244a4b56..98885753dd 100644 --- a/gnucash/import-export/log-replay/gnc-log-replay.c +++ b/gnucash/import-export/log-replay/gnc-log-replay.c @@ -233,12 +233,12 @@ static split_record interpret_split_record( char *record_line) } if (strlen(tok_ptr = my_strtok(NULL, "\t")) != 0) { - string_to_gnc_numeric(tok_ptr, &(record.amount)); + record.amount = gnc_numeric_from_string (tok_ptr); record.amount_present = TRUE; } if (strlen(tok_ptr = my_strtok(NULL, "\t")) != 0) { - string_to_gnc_numeric(tok_ptr, &(record.value)); + record.value = gnc_numeric_from_string (tok_ptr); record.value_present = TRUE; } if (strlen(tok_ptr = my_strtok(NULL, "\t")) != 0) diff --git a/libgnucash/app-utils/gnc-exp-parser.c b/libgnucash/app-utils/gnc-exp-parser.c index ebca57a74a..9d4545a82d 100644 --- a/libgnucash/app-utils/gnc-exp-parser.c +++ b/libgnucash/app-utils/gnc-exp-parser.c @@ -98,10 +98,9 @@ gnc_exp_parser_real_init ( gboolean addPredefined ) for (key = keys; key && *key; key++) { str_value = g_key_file_get_string(key_file, GEP_GROUP_NAME, *key, NULL); - if (str_value && string_to_gnc_numeric(str_value, &value)) - { + value = gnc_numeric_from_string (str_value); + if (!gnc_numeric_check (value)) gnc_exp_parser_set_value (*key, gnc_numeric_reduce (value)); - } } g_strfreev(keys); g_key_file_free(key_file); diff --git a/libgnucash/backend/xml/io-gncxml-v1.cpp b/libgnucash/backend/xml/io-gncxml-v1.cpp index 7791205dde..d7aecc4b18 100644 --- a/libgnucash/backend/xml/io-gncxml-v1.cpp +++ b/libgnucash/backend/xml/io-gncxml-v1.cpp @@ -472,6 +472,13 @@ simple_kvp_value_parser_new (sixtp_end_handler end_handler) */ +static gboolean +string_to_gnc_numeric(const gchar* str, gnc_numeric *n) +{ + *n = gnc_numeric_from_string (str); + return (!gnc_numeric_check (*n)); +} + /* ------------------------------------------------------------ */ /* generic type copnversion for kvp types */ #define KVP_CVT_VALUE(TYPE) \ diff --git a/libgnucash/backend/xml/sixtp-dom-parsers.cpp b/libgnucash/backend/xml/sixtp-dom-parsers.cpp index b1d30d2640..f59a0afd5b 100644 --- a/libgnucash/backend/xml/sixtp-dom-parsers.cpp +++ b/libgnucash/backend/xml/sixtp-dom-parsers.cpp @@ -509,8 +509,8 @@ dom_tree_to_gnc_numeric (xmlNodePtr node) if (!content) return gnc_numeric_zero (); - gnc_numeric num; - if (!string_to_gnc_numeric (content, &num)) + gnc_numeric num = gnc_numeric_from_string (content); + if (gnc_numeric_check (num)) num = gnc_numeric_zero (); g_free (content); diff --git a/libgnucash/backend/xml/sixtp-utils.cpp b/libgnucash/backend/xml/sixtp-utils.cpp index 0cf032b6ca..b65d547357 100644 --- a/libgnucash/backend/xml/sixtp-utils.cpp +++ b/libgnucash/backend/xml/sixtp-utils.cpp @@ -611,7 +611,8 @@ generic_gnc_numeric_end_handler (gpointer data_for_children, num = g_new (gnc_numeric, 1); if (num) { - if (string_to_gnc_numeric (txt, num)) + *num = gnc_numeric_from_string (txt); + if (!gnc_numeric_check (*num)) { ok = TRUE; *result = num;