Removing commas from Numbers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • crapycoder
    New Member
    • Nov 2008
    • 4

    Removing commas from Numbers

    Hi i have a Text File.
    the contents of which are as follows:

    name amount(per KiloGram) quantity(in KiloGrams) total($)
    rice 2$ 100 200
    sugar 10$ 1,000 10,000
    salt 5$ 500 2,500

    if i want to retrieve the quantity, when i display the value as 1000 in my form it is considering as string and showing me "1,000" because it has comma "," in between, also you can see in the amount in Total field.
    i am getting the same problem with total field also.

    i am using vb.net and i chose vb as programming language.

    can any one help to send me a code snippet to remove comma from a number
    (whatever may be the number, even in millions)

    Thanks
    CrapyCoder
  • nukefusion
    Recognized Expert New Member
    • Mar 2008
    • 221

    #2
    You can use the Replace method of the String object to remove the commas, i.e:

    Code:
    Dim myString As String = "1,000"
    myString.Replace(",", string.Empty)

    Comment

    • gsgurdeep
      New Member
      • Apr 2007
      • 94

      #3
      store comma separated value in a string.........
      Split it based on comma (,).........
      now join all parts of spited string in another string.........
      Convert this string in integer........ ..........
      & you got the results........ .....

      Comment

      • Xennex
        New Member
        • Jan 2009
        • 7

        #4
        You could try using the parse method of the "single" or "double" type..

        double.Parse("1 ,000,000")

        would give you

        1000000.0

        append the "ToString" method and you would get

        "1000000"

        Comment

        • Frinavale
          Recognized Expert Expert
          • Oct 2006
          • 9749

          #5
          I'd use the Double.Parse() method since it is a double that you want to work with in the first place.

          Another suggestion would be to use a MaskedTextBox to format the input in a way that is predictable to you. They are pretty cool :) Check them out.

          -Frinny

          Comment

          Working...