Currency
-
Hello fools.
Dim NewListBidAmount As Double = PostBidAmountTextBox.Text
I have the following code taking a value from a text box and using it else where. The value is a monetary value and therefore should only have two places after the decimal point. If I type in more than two places though the addtional places are stll shown when displayed and used elsewhere. How can I eradicate any digits that occur after the first two places after the .? Thanks -
Hello fools.
Dim NewListBidAmount As Double = PostBidAmountTextBox.Text
I have the following code taking a value from a text box and using it else where. The value is a monetary value and therefore should only have two places after the decimal point. If I type in more than two places though the addtional places are stll shown when displayed and used elsewhere. How can I eradicate any digits that occur after the first two places after the .? Thanks -
Hello fools.
Dim NewListBidAmount As Double = PostBidAmountTextBox.Text
I have the following code taking a value from a text box and using it else where. The value is a monetary value and therefore should only have two places after the decimal point. If I type in more than two places though the addtional places are stll shown when displayed and used elsewhere. How can I eradicate any digits that occur after the first two places after the .? ThanksI had a project where I needed to restrict decimal point places also. I wrote this method:
Public Sub RestrictDecimalPlaces(ByVal txtSender As TextBox, ByVal intPlacesToTheRight As Integer) '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* ' This function will ensure that only one decimal point is allowed in a text box ' and that the user may only type in a certain number of digits to the right of ' the decimal point (as specified by the intPlacesToTheRight parm). '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* If txtSender.TextLength <> 0 Then Dim strTemp As String = txtSender.Text Dim straTemp() As String straTemp = strTemp.Split(".") Select Case straTemp.Length Case 1 'No decimal point, so no problem Return Case 2 'One decimal point, ensure specified chars to the right Select Case straTemp(1).Length Case Is > intPlacesToTheRight txtSender.Text = straTemp(0) & "." & straTemp(1).PadRight(intPlacesToTheRight, "0").Substring(0, intPlacesToTheRight) txtSender.SelectionStart = txtSender.Text.Length End Select Case Else 'More than one decimal point, remove extra txtSender.Text = straTemp(0) & "." & straTemp(1) txtSender.SelectionStart = txtSender.Text.Length End Select End If End Sub
And used it in the KeyPress Event of textboxes I wanted to restrict, like this:
Private Sub txtInput\_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtInput.KeyUp RestrictDecimalPlaces(sender, 4) End Sub
However, I know this code still has some quirks...and it won't help when the user does a copy and paste into the textbox, so you will want to modify it or use other edits as well. Hope this helps.
-
Hello fools.
Dim NewListBidAmount As Double = PostBidAmountTextBox.Text
I have the following code taking a value from a text box and using it else where. The value is a monetary value and therefore should only have two places after the decimal point. If I type in more than two places though the addtional places are stll shown when displayed and used elsewhere. How can I eradicate any digits that occur after the first two places after the .? Thanks -
Thanks for that