#!/usr/bin/perl
# Filename: kb_converter.pl
# Description: Convert values from Bytes to KiloBytes
use strict;
my $val;
my $argc = @ARGV;
if($argc == 1) {
$val = shift;
} else {
$val = 12345;
}
# 1KB = 1024Bytes
my $val_kb = $val / 1024;
my $val_kb_rounded = sprintf("%.2f", $val / 1024);
print "Not Rounded Answer:\n$val Bytes = $val_kb KB\n";
print "Rounded Answer:\n$val Bytes = $val_kb_rounded KB\n";
All I ever wish is that you will gain something from the examples I wrote in this blog. If you have suggestions, questions, or have a much better way of doing it, please feel free to drop your comments so I may also learn from it and also those who are crawling around this blog. Examples here are mostly about Unix/Linux administration and programming which varies from C, C++, C#, Java, Shell Scripting, PHP to Python and I hope I can post more.
Monday, November 10, 2008
Perl: Rounding off Decimal Digits
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment