Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Displaying long floats without scientific notation

Reply
Thread Tools

Displaying long floats without scientific notation

 
 
sa 125
Guest
Posts: n/a
 
      12-10-2008
Hello -

I need to display the long forms of numbers read from a database table
without scientific notation.

For example, a number read as 1.5e-6 should be displayed as "0.0000015",
and so on.

Is there an easy way to do this in ruby, or do I need to write a
function to do it? I was thinking about using a lot of
number.to_s.split...

Thanks!
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Michael Libby
Guest
Posts: n/a
 
      12-10-2008
On Wed, Dec 10, 2008 at 8:28 AM, sa 125 <(E-Mail Removed)> wrote:
> Hello -
>
> I need to display the long forms of numbers read from a database table
> without scientific notation.
>
> For example, a number read as 1.5e-6 should be displayed as "0.0000015",
> and so on.
>
> Is there an easy way to do this in ruby, or do I need to write a
> function to do it? I was thinking about using a lot of
> number.to_s.split...


Use a formatted print statement.

printf("%.7f\n", 0.0000015)

You will need to adjust the first parameter to taste.

You can read about string formatting at your command line with: ri
Kernel.sprintf

There is also an alternative syntax, see: ri String.%

-Michael

--
Michael C. Libby
www.mikelibby.com

 
Reply With Quote
 
 
 
 
sa 125
Guest
Posts: n/a
 
      12-11-2008
That's what I needed, thanks.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Scientific Notation Conversion N1GHTS C++ 1 02-20-2008 07:22 PM
How to represent the scientific notation? asdf C++ 2 10-21-2006 04:12 PM
reguarding scientific notation grinder C Programming 7 08-29-2006 09:26 PM
Scientific Notation Dustan Python 7 12-04-2005 01:56 PM
No scientific notation? Ville Ahonen C++ 2 10-19-2004 10:08 PM



Advertisments