Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Currency

Currency

Scheduled Pinned Locked Moved ASP.NET
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sam Heller
    wrote on last edited by
    #1

    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

    S K R 3 Replies Last reply
    0
    • S Sam Heller

      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

      S Offline
      S Offline
      SABhatti
      wrote on last edited by
      #2

      use formatcurrency(amount,2) before displaying it ..

      -----

      1 Reply Last reply
      0
      • S Sam Heller

        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

        K Offline
        K Offline
        Kschuler
        wrote on last edited by
        #3

        I 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.

        1 Reply Last reply
        0
        • S Sam Heller

          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

          R Offline
          R Offline
          rajmani
          wrote on last edited by
          #4

          Hello fool.

          S 1 Reply Last reply
          0
          • R rajmani

            Hello fool.

            S Offline
            S Offline
            Sam Heller
            wrote on last edited by
            #5

            Thanks for that

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups