[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Jesse Crockett

8/28/2008 11:23:00 AM

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-....

1 Answer

Jesse Crockett

8/28/2008 12:00:00 PM

0

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-....