Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
English
Round a decimal variable to 2 decimal digits
Message
General information
Fórum:
ASP.NET
Category:
Miscellaneous
ID da thread:
00738295
ID da mensagem:
00738301
Views:
27
Hi Roland,

To round, you use static method System.Math.Round(nNumber, nDigits)
dTotal = System.Math.Round(dPrice * dTaxRate,2)
To work with Textboxes, you need to use the Text property of the Textbox to extract the value entered in the control
dTotal = CDec(cbPrice.Text) * dTaxRate
>Can you set a textbox to a datatype?

Textbox.Text property must always be set to a string. You need to convert it to other data types when you extract it's value.

>Can you set a format to decimal with length 10 with 2 decimals?

To format textboxes, you need to use the techniques shown in message #670154

>Hi,
>
>How do you round a calculation like the following?
>
>dim dTotal as Decimal = 0
>dim dTaxPerc as Decimal = .0725
>dim dPrice as decimal = 0
>
>dTotal = dPrice * dTaxRate (Rounded to 2 deciaml places)
>
>Also, how do you add, subtract, divide using textboxes in forms?
>I have tried and get systax errors. cdec(cbPrice)
>
>Textbox cbPrice
>
>dTotal = cdec(cbPrice) * dTaxRate
>
>Whats the secret?
>
>Can you set a textbox to a datatype?
>Can you set a format to decimal with length 10 with 2 decimals?
>
>Thanks
>Roland
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Responder
Mapa
View

Click here to load this message in the networking platform