L
Lars Haugseth
|
| Thus spoke Lars Haugseth (on 2006-05-29 12:50):
|
| > This ought to do the trick:
| >
| > s/(\.\d+?)0+(?!\d)/$1/g;
|
| $text = "200.,200.0000";
| $text =~ s/(\.\d+?)0+(?!\d)/$1/g;
| print "$text\n";
|
| => 200.,200.0
The OP did not specify how special circumstances like these should
be handled.
If numbers with no fractional part should be converted to integers,
something like this will do:
s/(\.\d+?)0+(?!\d)/$1/g; # same as before
s/\.0*(?!\d)//g;
Combining these two into a single regex is left as an exercise
to the reader.
| Thus spoke Lars Haugseth (on 2006-05-29 12:50):
|
| > This ought to do the trick:
| >
| > s/(\.\d+?)0+(?!\d)/$1/g;
|
| $text = "200.,200.0000";
| $text =~ s/(\.\d+?)0+(?!\d)/$1/g;
| print "$text\n";
|
| => 200.,200.0
The OP did not specify how special circumstances like these should
be handled.
If numbers with no fractional part should be converted to integers,
something like this will do:
s/(\.\d+?)0+(?!\d)/$1/g; # same as before
s/\.0*(?!\d)//g;
Combining these two into a single regex is left as an exercise
to the reader.