$content =~ s/(\d\d\.\d*)/sprintf("%.6f",$1);/ge; #round to 6 decimal +digits
One can avoid hard-coding the rounding precision by using either
my $n = $some_integer;
... sprintf("%.${n}f", $1) ...
or the "wildcard" (if that's the right term (update: maybe "placeholder"?)) format specifier
... sprintf('%.*f', $n, $1) ...
Update: In the code above, I've implied that $n must be an integer. Interestingly (for some definition of "interesting"), if it is not, then the first code example ($n interpolated) screws up, but the second (* wildcard specifier) behaves "properly", DWIMishly ignoring the fractional part of the numeric value. (I haven't checked yet to see if this behavior is the same as in C/C++/D/etc.)
Give a man a fish: <%-{-{-{-<
In reply to Re^2: In-place regex substitution
by AnomalousMonk
in thread In-place regex substitution
by lmocsi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |