Decimal datatype and trailing zeros

Hello
I’ve encountered a little problem with zeros using the decimal data
type
Specifying a scale of 3 and inserting a number with 3 zeros after the
point (for example 12345.000) it gets correctly stored in the
database, but rails insists to show me the number only with the first
zero after the point (12345.0)
There is a way to tell rails to not truncate at the first zero?

On Mon, Aug 3, 2009 at 11:37 AM, lucac81[email protected] wrote:

There is a way to tell rails to not truncate at the first zero?

You can use sprintf to always force printing up to 3 decimal places,
eg

sprintf “%.3f”, the_number

On 03 Aug 2009, at 12:20, Franz S. wrote:

There is a way to tell rails to not truncate at the first zero?

You can use sprintf to always force printing up to 3 decimal places,
eg

sprintf “%.3f”, the_number

Or even better: number_with_precision

Best regards

Peter De Berdt

On Aug 3, 12:29 pm, Peter De Berdt [email protected] wrote:

http://api.rubyonrails.org/classes/ActionView/Helpers/NumberHelper.ht

Best regards

Peter De Berdt

That should do the trick, i’ll try later

Thank you very much

Luca

On Aug 3, 3:43 pm, lucac81 [email protected] wrote:

That should do the trick, i’ll try later

Thank you very much

Unfortunately this work only in the views, my program has to generate
a text file, and in the file the number is still truncated
I need to find another solution
Luca

The short, quick way to do it in any context is with plain Ruby:

“%.03f” % value

–Matt J.