How to format decimals on the fly (for EOF blocks)?

Discussion in 'Ruby' started by Jesse Crockett, Aug 28, 2008.

  1. Hello, I'm facing a problem where, for instance, 7mcg of Nutrient is
    required per day. It's scaled in the db to 3 (or more) decimal places,
    but on the page, often there will show

    Nutrient 0 mcg 8%

    -- otherwise ... 0.4423 mcg 8%

    My figures are for demonstration only :)

    Is there a way to covert the latter mcg figure to 0.4 on the fly? Or do
    I need to work on the database, since these are mainly for string <<EOF
    output?
    --
    Posted via http://www.ruby-forum.com/.
     
    Jesse Crockett, Aug 28, 2008
    #1
    1. Advertising

  2. sprintf !

    Jesse Crockett wrote:
    > Hello, I'm facing a problem where, for instance, 7mcg of Nutrient is
    > required per day. It's scaled in the db to 3 (or more) decimal places,
    > but on the page, often there will show
    >
    > Nutrient 0 mcg 8%
    >
    > -- otherwise ... 0.4423 mcg 8%
    >
    > My figures are for demonstration only :)
    >
    > Is there a way to covert the latter mcg figure to 0.4 on the fly? Or do
    > I need to work on the database, since these are mainly for string <<EOF
    > output?


    --
    Posted via http://www.ruby-forum.com/.
     
    Jesse Crockett, Aug 28, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hansiman
    Replies:
    1
    Views:
    19,545
    =?Utf-8?B?S2VuIENveCBbTWljcm9zb2Z0IE1WUF0=?=
    Oct 8, 2004
  2. Kobu
    Replies:
    10
    Views:
    657
    Keith Thompson
    Mar 4, 2005
  3. SpreadTooThin

    ifstream eof not reporting eof?

    SpreadTooThin, Jun 13, 2007, in forum: C++
    Replies:
    10
    Views:
    712
    James Kanze
    Jun 15, 2007
  4. matt
    Replies:
    1
    Views:
    287
    George Ogata
    Aug 6, 2004
  5. Jan Burse
    Replies:
    67
    Views:
    1,104
    Jan Burse
    Mar 14, 2012
Loading...

Share This Page