Removing commas from numbers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shrutisinha
    New Member
    • Feb 2007
    • 25

    Removing commas from numbers

    I need a help in perl as very new to perl
    I have balance 1,00.00 and want to change it to 1000.00
    I want to remove "," from my balance
    I am doing parsing my orignal record has a "," in my balance and want to remove that come
    I can't understand what can i do to remove that in perl, may be there is replace fuction or something , somebody plese help me with this issue

    Thanks
    Last edited by Shrutisinha; Apr 18 '07, 05:31 PM. Reason: add signature and change title name
  • KevinADC
    Recognized Expert Specialist
    • Jan 2007
    • 4092

    #2
    Code:
    $string - '1,000.00';
    $string =~ tr/,/d;

    Comment

    • Shrutisinha
      New Member
      • Feb 2007
      • 25

      #3
      Originally posted by KevinADC
      Code:
      $string - '1,000.00';
      $string =~ tr/,/d;
      http://perldoc.perl.org/index-tutorials.html
      Do i have to put in loop bez all my number don't have ","
      some are 800.50
      765.34
      1,234.80
      so nervious with perl
      thanks

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        if there is no comma in the number nothing will happen.

        Comment

        • ghostdog74
          Recognized Expert Contributor
          • Apr 2006
          • 511

          #5
          another way
          Code:
                  $num = '1,202,445.00';
                  $num =~ s/,//g;

          Comment

          • KevinADC
            Recognized Expert Specialist
            • Jan 2007
            • 4092

            #6
            I see my code was not correct, this line:

            Code:
            $string =~ tr/,/d;
            should be:

            Code:
            $string =~ tr/,//d;

            Comment

            • savanm
              New Member
              • Oct 2006
              • 85

              #7
              hi,


              @temp = ("1,000.00","2, 000.00");

              foreach $temp(@temp)
              {
              $temp=~s/,//sgi;
              print "\n$temp";
              }

              otherwise u should store entire file into a single variable and use a regex as follows(My Point of view only)

              $temp=~s/([0-9]),([0-9]+)\.([0-9])/$1$2$3;

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                $temp=~s/,//sgi;

                "s" and "i" have no effect in this context

                the tr/// operator is better used for this type of simple task. It is more efficient than using s///.

                Comment

                • Shrutisinha
                  New Member
                  • Feb 2007
                  • 25

                  #9
                  Originally posted by KevinADC
                  $temp=~s/,//sgi;

                  "s" and "i" have no effect in this context

                  the tr/// operator is better used for this type of simple task. It is more efficient than using s///.

                  thanks a lot .. it worked , thanks you lot guys for all your help

                  Comment

                  • savanm
                    New Member
                    • Oct 2006
                    • 85

                    #10
                    hi,

                    yes kevin i accept ur concept,

                    Thanx

                    Comment

                    Working...