Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

File Size Calculator
Hi all, I'm trying to writing a script that will allow a user to enter a
number and that number will be converted into KB,MB or GB depending on the
size of the number. Can someone point me in the right direction?

Example:
user enter: 59443
Script will output: 58M


SilverFox

Report this thread to moderator Post Follow-up to this message
Old Post
Silverfox
08-09-04 08:56 PM


Re: File Size Calculator
On 9 Aug 2004, at 14:34, SilverFox wrote:

> Hi all, I'm trying to writing a script that will allow a user to enter
> a
> number and that number will be converted into KB,MB or GB depending on
> the
> size of the number. Can someone point me in the right direction?

What have you got so far? Where are you stuck? Getting user input
(where from)? Working out which order of magnitude the number is?
Converting between kilo and mega et al? Showing the output?

Show us some code.

--
David Dorward
<http://dorward.me.uk/>
<http://blog.dorward.me.uk/>


Report this thread to moderator Post Follow-up to this message
Old Post
David Dorward
08-09-04 08:56 PM


Re: File Size Calculator
On Mon, 9 Aug 2004, SilverFox wrote:

> Example:
> user enter: 59443
> Script will output: 58M

I know this isn't getting into the spirit of things, but have you
considered simply using the `units` program?

% units
500 units, 54 prefixes
You have: 59443 bytes
You want: megabytes
* 0.056689262
/ 17.640025
You have: 59443 bytes
You want: kilobytes
* 59.443
/ 0.016822839
You have: ^C
% units bytes kilobytes
* 0.001
/ 1000

% units bytes megabytes
* 9.5367432e-07
/ 1048576

The nice thing about `units` -- in this context -- is that it lets the
user pick the conversion units they want to work with, and also gives
hints for converting both to & from the alternate measurement scale.

Of course, working this into a larger program that does other things
might be annoying -- in which case your way is better -- but if all you
want is the conversions, this is a solved problem :-)


--
Chris Devers

Report this thread to moderator Post Follow-up to this message
Old Post
Chris Devers
08-09-04 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:33 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.