LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-26-2005, 12:37 PM   #1
Ateo
Member
 
Registered: Sep 2004
Location: http://longbeach.ca.u$
Distribution: Ubuntu,Gentoo, OSX
Posts: 136

Rep: Reputation: 15
Perl assistance requested...


I'm trying to create a small script that converts MB to GB for a karamba theme so that my memory and hard drives display in GB rather than MB when over 1000MB. This is what I have thus far but it doesn't produce what I need:

Code:
#!/usr/bin/perl -w

use strict;

my $value = $ARGV[0];

if ( $value > 1000 )
{
  $value = sprintf "%f", ( $value / 1000 );
}

print $value . "\n\n";
Produces:

Code:
~ $ ./test.pl 19335
19.335000
I was hoping for 19.34 but I'm just not getting it.

Any assistance would be much appreciated.

Thanks
 
Old 05-26-2005, 01:05 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
I think what you want is:
$value = sprintf "%.2f", ( $value / 1000 );

Last edited by david_ross; 05-26-2005 at 01:06 PM.
 
Old 05-26-2005, 03:01 PM   #3
Ateo
Member
 
Registered: Sep 2004
Location: http://longbeach.ca.u$
Distribution: Ubuntu,Gentoo, OSX
Posts: 136

Original Poster
Rep: Reputation: 15
Thanks. That worked...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
perl assistance... Ateo Programming 8 07-02-2005 08:07 PM
bash assistance requested.. Ateo Programming 3 02-09-2005 06:41 PM
Assistance Requested: Hardware selection for linux servers the_halfling Linux - Hardware 2 05-05-2004 07:05 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
perl/sendmail/mailfilter help requested joesbox Programming 1 03-04-2003 11:07 AM


All times are GMT -5. The time now is 07:29 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration