Divide European decimal with TextBox value using C# and VB.Net in ASP.Net

elvisidrizi1
 
on Aug 03, 2020 11:30 PM
Sample_484175.zip
944 Views

Hello Everyone,

I do calculations with data that comes from SQL and with TextBox that I insert by myself.

An example is like this: 54,39 with EURO sign is divided by 3 which leads to this number 1813, it should be 18,13.

This is the code:

Labalsum.Text = LabelTotal.Text / textDivide.Text

LabelTotal.text shows information from SQL, a number which contains EURO sign in it and textDivide.text is a text box which the user can insert to divide. This works fine and the calculation is fine just the comma appears somewhere else making the result really big number.

Thankfully, Elvis

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Aug 04, 2020 01:48 AM

Hi elvisidrizi1,

Check this example. Now please take its reference and correct your code.

HTML

Total : <asp:Label ID="LabelTotal" runat="server" Text="54,39 €" /><br />
<asp:TextBox ID="textDivide" runat="server" /><br /><br />
<asp:Button Text="Calculate" runat="server" OnClick="OnCalculate" /><hr />
<asp:Label ID="Labalsum" runat="server" />

Code

C#

protected void OnCalculate(object sender, EventArgs e)
{
    Labalsum.Text = (Convert.ToDecimal(LabelTotal.Text.Trim().Replace(",", ".").Replace("€", ""))
                    / Convert.ToDecimal(textDivide.Text)).ToString().Replace(".", ",") + " €";
}

VB.Net

Protected Sub OnCalculate(ByVal sender As Object, ByVal e As EventArgs)
    Labalsum.Text = (Convert.ToDecimal(LabelTotal.Text.Trim().Replace(",", ".").Replace("€", "")) _
                    / Convert.ToDecimal(textDivide.Text)).ToString().Replace(".", ",") & " €"
End Sub

Screenshot