Bug 605602 - precision of Financial Calculator seems to depend on locale

* 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.
This commit is contained in:
Christopher Lam 2019-08-23 21:14:38 +08:00
parent 90da06b8af
commit 13d3179729
2 changed files with 61 additions and 7 deletions

View File

@ -68,6 +68,7 @@ struct _FinCalcDialog
GtkWidget *payment_combo;
GtkWidget *end_of_period_radio;
GtkWidget *precision;
GtkWidget *discrete_compounding_radio;
GtkWidget *payment_total_label;
@ -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 *****************************************************/
@ -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;
@ -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);
@ -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)
{
@ -427,7 +434,6 @@ calc_value(FinCalcDialog *fcd, FinCalcValue value)
fi_calc_future_value(&fcd->financial_info);
break;
default:
PERR("Unknown financial variable");
break;
}
@ -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,
@ -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))
@ -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;

View File

@ -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>
@ -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>