Format number to two decimal point using FormatNumber function in VB.Net

elvisidrizi1
 
on Aug 04, 2020 11:41 PM
1022 Views

Hello,

I do some calculation vb.net and I get results with a lot of numbers behind.

This is one of the codes that I have and I get a lot of digits behind:

Labalsum.Text = (Convert.ToDecimal(LabelTotal.Text.Trim().Replace(".", ",").Replace("€", "")) _
                / Convert.ToDecimal(textDivide.Text)).ToString().Replace(".", ",") & " €"

And this is another code (Simpler) that takes value from above and also it gives me a lot of fo digits behind : 

'Label11.Text = LabelA.Text - Labalsum.Text
'Label12.Text = LabelE.Text - Labalsum.Text
'Label13.Text = LabelE2s.Text - Labalsum.Text

Thank you a lot, Blessings

Download FREE API for Word, Excel and PDF in ASP.Net: Download
elvisidrizi1
 
on Aug 05, 2020 12:01 AM

This is a modified answer :

Label11.Text = (Convert.ToDecimal(LabelAlisa.Text.Trim().Replace(".", ",").Replace("€", "")) _
                     - Convert.ToDecimal(Labalsum.Text)).ToString().Replace(".", ",") & " €"

        Label12.Text = (Convert.ToDecimal(LabelEnis.Text.Trim().Replace(".", ",").Replace("€", "")) _
                     - Convert.ToDecimal(Labalsum.Text)).ToString().Replace(".", ",") & " €"

        Label13.Text = (Convert.ToDecimal(LabelElvis.Text.Trim().Replace(".", ",").Replace("€", "")) _
                     - Convert.ToDecimal(Labalsum.Text)).ToString().Replace(".", ",") & " €"

and I used this to remove the numbers behind :

Labalsum.Text = FormatNumber(Labalsum.Text, 2)

Thank you