alexandr
alexandr

Reputation: 41

How to format decimals

I need to format float like price for two decimal places and thousands spaces, like this: "1 082 233.00"

Upvotes: 2

Views: 1105

Answers (1)

Pär Wieslander
Pär Wieslander

Reputation: 28934

Use number_to_currency or number_with_precision:

number_with_precision(1082233, :precision => 2,
                               :separator => '.',
                               :delimiter => ' ')
# => '1 082 233.00'

See the NumberHelper documentation for details.

Upvotes: 10

Related Questions