Forum: Ruby Displaying long floats without scientific notation

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
7db3b1680807d393d40260591b4ae5e0?d=identicon&s=25 sa 125 (sa125)
on 2008-12-10 15:34
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

26a81e5badb9e002ab9ed3542036e584?d=identicon&s=25 Michael Libby (Guest)
on 2008-12-10 15:54
(Received via mailing list)
On Wed, Dec 10, 2008 at 8:28 AM, sa 125 <> wrote:
> 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

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

7db3b1680807d393d40260591b4ae5e0?d=identicon&s=25 sa 125 (sa125)
on 2008-12-11 08:44
That's what I needed, thanks.
This topic is locked and can not be replied to.