perl or shell to round last column to hundredths place

perl or shell to round last column to hundredths place. I have a sample file below.
so4pap.txt
libertyforall2Asked:
Who is Participating?
 
Dushyant SharmaConnect With a Mentor Commented:
awk '{print $1 " " $2 " " $3 " "  $4/1}' so4pap.txt

you need to set the scale
0
 
FishMongerCommented:
What have you tried?
0
 
parparovConnect With a Mentor Commented:
Usage: script.pl < so4pap.txt

#!/usr/bin/perl

use strict;
use warnings;

while (<>) {
	chomp;
	my @data = split(/\s+/);
	$data[-1] = sprintf("%0.2f\n", $data[-1]);
	print join(" ", @data);
}

Open in new window

0
 
libertyforall2Author Commented:
Great!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.