mindserve
asked on
Convert string to decimal and do computations on it
I have a vb 2005 application. Right now I am using Access as the backend database. Instead of using Currency and percentage data types in the database, I have them as text or string data types.
I am able to convert the string to decimal and format for percentage and currency so that the textboxes show the correct values like the example below:
-------------------------- ---------- ---------- ---------- ---------- ---
Private Sub txtRetailDisc_Validated(By Val sender As Object, ByVal e As System.EventArgs) Handles txtRetailDisc.Validated
Dim PercentageRate As Decimal = CDec(txtRetailDisc.Text)
txtRetailDisc.Text = FormatPercent(PercentageRa te)
End Sub
-------------------------- ---------- ---------- ---------- ---------- ---------
Here is my problem and question.
I need to take the value of txtRetailPrice and multiply it by the txtRetailDisc textbox to show the value in the txtDiscountPrice.text ( textbox)
I either can't get a result or get a mismatch when I try to do this.
Is there a way to convert a string and then do computations on it or should I change the data types in the database. I have tried that, but I cannot get Currency or percentages to format in the vb 2005 program.
I am not using any bound data controls either, this is all being done through code.
I am able to convert the string to decimal and format for percentage and currency so that the textboxes show the correct values like the example below:
--------------------------
Private Sub txtRetailDisc_Validated(By
Dim PercentageRate As Decimal = CDec(txtRetailDisc.Text)
txtRetailDisc.Text = FormatPercent(PercentageRa
End Sub
--------------------------
Here is my problem and question.
I need to take the value of txtRetailPrice and multiply it by the txtRetailDisc textbox to show the value in the txtDiscountPrice.text ( textbox)
I either can't get a result or get a mismatch when I try to do this.
Is there a way to convert a string and then do computations on it or should I change the data types in the database. I have tried that, but I cannot get Currency or percentages to format in the vb 2005 program.
I am not using any bound data controls either, this is all being done through code.
ASKER
Well, Microsoft has alot of info but I need an example of how to do this. Do you know of any?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I keep getting errors for some reason. Says Input string is not in the correct format...
ASKER
Ok, I had to remove the previous formatting I had entered. Now it works.
http://msdn2.microsoft.com/en-us/library/system.decimal.parse.aspx
To round a decimal variable
Decimal.Round(VariableName
http://msdn2.microsoft.com/en-us/library/system.decimal.round.aspx
To integrate the decimal variable in a string
String.Format("The formatted decimal {0}.", VariableName)
I hope this information is helpful.