I am using Active Perl 5.8.8.
I am trying to remove trailing zeros from floating point numbers.
I also want to remove the decimal point if there is no decimal component.
eg
[ul]
[li]1.100 => 1.1[/li]
[li]2.020 => 2.02[/li]
[li]3.003 => 3.003[/li]
[li]4.000 => 4[/li]
[/ul]
This is what I have:
This snippet works fine, but I was wondering if there was a better, more elegant way to do this that did not require multiple capture buffers.
(something like perl 5.10s (?|pattern)).
Thank you for your time.
I am trying to remove trailing zeros from floating point numbers.
I also want to remove the decimal point if there is no decimal component.
eg
[ul]
[li]1.100 => 1.1[/li]
[li]2.020 => 2.02[/li]
[li]3.003 => 3.003[/li]
[li]4.000 => 4[/li]
[/ul]
This is what I have:
Code:
{
no warnings 'uninitialized';
$_ =~ s/^(\d+\.0*[1-9]+)0*$|^(\d+)\.0+$/$1$2/;
}
This snippet works fine, but I was wondering if there was a better, more elegant way to do this that did not require multiple capture buffers.
(something like perl 5.10s (?|pattern)).
Thank you for your time.