Skip to content

Commit

Permalink
Bug 605602 - precision of Financial Calculator seems to depend on locale
Browse files Browse the repository at this point in the history
* the calc_clicked_cb had mechanism to abort if no fields were
  empty. disable it.

* to convert gnc_numeric to string, the only suitable print_info is
  gnc_share_print_info_places which takes decimal and outputs suitable
  print_info. Not very appropriate, but works.
  • Loading branch information
christopherlam committed Aug 27, 2019
1 parent 90da06b commit 13d3179
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 7 deletions.
26 changes: 20 additions & 6 deletions gnucash/gnome/dialog-fincalc.c
Expand Up @@ -68,6 +68,7 @@ struct _FinCalcDialog
GtkWidget *payment_combo;

GtkWidget *end_of_period_radio;
GtkWidget *precision;
GtkWidget *discrete_compounding_radio;

GtkWidget *payment_total_label;
Expand Down Expand Up @@ -99,6 +100,7 @@ void fincalc_update_calc_button_cb(GtkWidget *unused, FinCalcDialog *fcd);
void fincalc_calc_clicked_cb(GtkButton *button, FinCalcDialog *fcd);
void fincalc_compounding_radio_toggled(GtkToggleButton *togglebutton, gpointer data);
void fincalc_amount_clear_clicked_cb(GtkButton *button, FinCalcDialog *fcd);
void fincalc_precision_spin_value_changed_cb (GtkButton *button, FinCalcDialog *fcd);
void fincalc_response_cb (GtkDialog *dialog, gint response, FinCalcDialog *fcd);

/** Implementations *****************************************************/
Expand Down Expand Up @@ -128,7 +130,7 @@ normalize_period(unsigned int *period)
static void
fi_to_gui(FinCalcDialog *fcd)
{
const gnc_commodity *commodity;
int precision;
static char string[64];
gnc_numeric total;
gnc_numeric npp;
Expand All @@ -153,12 +155,11 @@ fi_to_gui(FinCalcDialog *fcd)

pmt = double_to_gnc_numeric (fcd->financial_info.pmt, 100000, GNC_HOW_RND_ROUND_HALF_UP);

commodity = gnc_default_currency ();
precision = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(fcd->precision));

total = gnc_numeric_mul (npp, pmt, gnc_commodity_get_fraction (commodity),
GNC_HOW_RND_ROUND_HALF_UP);
total = gnc_numeric_mul (npp, pmt, GNC_DENOM_AUTO, GNC_HOW_RND_ROUND);

xaccSPrintAmount (string, total, gnc_default_print_info (FALSE));
xaccSPrintAmount (string, total, gnc_share_print_info_places (precision));
gtk_label_set_text (GTK_LABEL(fcd->payment_total_label), string);

i = normalize_period(&fcd->financial_info.CF);
Expand Down Expand Up @@ -280,6 +281,12 @@ fincalc_amount_clear_clicked_cb(GtkButton *button, FinCalcDialog *fcd)
gtk_entry_set_text(edit, "");
}

void
fincalc_precision_spin_value_changed_cb (GtkButton *button, FinCalcDialog *fcd)
{
gtk_widget_set_sensitive (GTK_WIDGET(fcd->calc_button), TRUE);
}

static void
init_fi(FinCalcDialog *fcd)
{
Expand Down Expand Up @@ -427,7 +434,6 @@ calc_value(FinCalcDialog *fcd, FinCalcValue value)
fi_calc_future_value(&fcd->financial_info);
break;
default:
PERR("Unknown financial variable");
break;
}

Expand All @@ -450,6 +456,7 @@ fincalc_calc_clicked_cb(GtkButton *button, FinCalcDialog *fcd)
calc_value(fcd, i);
return;
}
calc_value(fcd, NUM_FIN_CALC_VALUES);
}

void fincalc_response_cb (GtkDialog *dialog,
Expand Down Expand Up @@ -555,8 +562,10 @@ gnc_ui_fincalc_dialog_create(GtkWindow *parent)
GtkWidget *button;
GtkWidget *combo;
GtkWidget *edit;
GtkWidget *spin;
GtkWidget *hbox;
GtkBuilder *builder;
GtkAdjustment *adjustment;

if (gnc_forall_gui_components (DIALOG_FINCALC_CM_CLASS,
show_handler, NULL))
Expand Down Expand Up @@ -655,6 +664,11 @@ gnc_ui_fincalc_dialog_create(GtkWindow *parent)
g_signal_connect(fcd->compounding_combo, "changed",
G_CALLBACK (fincalc_update_calc_button_cb), fcd);

spin = GTK_WIDGET (gtk_builder_get_object (builder, "precision_spin"));
adjustment = gtk_adjustment_new (2, 0, 10, 1, 1, 1);
gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON(spin), adjustment);
fcd->precision = spin;

button = GTK_WIDGET(gtk_builder_get_object (builder, "period_payment_radio"));
fcd->end_of_period_radio = button;

Expand Down
42 changes: 41 additions & 1 deletion gnucash/gtkbuilder/dialog-fincalc.glade
Expand Up @@ -477,6 +477,46 @@
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkBox" id="vbox83">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="label803">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Precision</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkSpinButton" id="precision_spin">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="input_purpose">number</property>
<property name="climb_rate">1</property>
<property name="numeric">True</property>
<property name="value">1</property>
<signal name="value-changed" handler="fincalc_precision_spin_value_changed_cb" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkAlignment" id="alignment31">
<property name="visible">True</property>
Expand Down Expand Up @@ -509,7 +549,7 @@
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">5</property>
<property name="position">6</property>
</packing>
</child>
</object>
Expand Down

0 comments on commit 13d3179

Please sign in to comment.