How to format the CalcQuick result?
Description
By default, the values from the particular key in CalcQuick are returned as an object value. This value can be converted as a string by using ToString() method. As separate support is not provided to format the result of the CalcQuick, the result is formatted as the following suggested way.
Solution
To format the result of the CalcQuick calculations, the result can be parsed by using any of the formatting methods. For example,
- int.Parse
- double.Parse
- decimal.Parse
C#
private void calculateBtn_Click(object sender, EventArgs e) { //Reassigns the key values to the CalcQuick calculator["A"] = this.value1Text.Text; calculator["B"] = this.value2Text.Text; calculator["C"] = this.formulaText.Text; //Used to recalculate the all formulas in CalcQuick calculator.SetDirty(); //Formats the result string after parsed as double this.resultText.Text = double.Parse(calculator["C"].ToString()).ToString("#,##0.00"); }
VB
Private Sub calculateBtn_Click(ByVal sender As Object, ByVal e As EventArgs) Handles calculateBtn.Click 'Reassigns the formula if changed calculator("A") = Me.value1Text.Text calculator("B") = Me.value2Text.Text calculator("C") = Me.formulaText.Text 'Used to recalculate the all formulas in CalcQuick calculator.SetDirty() 'Formats the result string after parsed as double Me.resultText.Text = Double.Parse(calculator("C").ToString()).ToString("#,##0.00") End Sub
The SetDirty() method is used for every calculations. I.e. whenever you are calculating the formulas with different values.
Refer to the following screenshot.
Sample Links: