Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageOn 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/>
Post Follow-up to this messageOn 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.