469,281 Members | 2,484 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

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
Apr 18 '07 #1
9 11897
KevinADC
4,059 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. $string - '1,000.00';
  2. $string =~ tr/,/d; 
http://perldoc.perl.org/index-tutorials.html
Apr 18 '07 #2
Expand|Select|Wrap|Line Numbers
  1. $string - '1,000.00';
  2. $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
Apr 18 '07 #3
KevinADC
4,059 Expert 2GB
if there is no comma in the number nothing will happen.
Apr 18 '07 #4
ghostdog74
511 Expert 256MB
another way
Expand|Select|Wrap|Line Numbers
  1.         $num = '1,202,445.00';
  2.         $num =~ s/,//g; 
  3.  
Apr 19 '07 #5
KevinADC
4,059 Expert 2GB
I see my code was not correct, this line:

Expand|Select|Wrap|Line Numbers
  1. $string =~ tr/,/d; 
should be:

Expand|Select|Wrap|Line Numbers
  1. $string =~ tr/,//d; 
Apr 19 '07 #6
savanm
85
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;
Apr 19 '07 #7
KevinADC
4,059 Expert 2GB
$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///.
Apr 19 '07 #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///.

thanks a lot .. it worked , thanks you lot guys for all your help
Apr 20 '07 #9
savanm
85
hi,

yes kevin i accept ur concept,

Thanx
Apr 21 '07 #10

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by David Sharp | last post: by
4 posts views Thread by koray | last post: by
7 posts views Thread by AES | last post: by
7 posts views Thread by svm | last post: by
3 posts views Thread by Robert Scheer | last post: by
14 posts views Thread by Adrienne Boswell | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.