When rendering a number, you want to pretty up the string coming from #to_s
:
0.0
as 0
.
to ,
in some European countriesnil
The attached helper that does just that. Some usage examples with their resulting strings:
Invocation | Result |
---|---|
amount(0) |
0 |
amount(0.0) |
0 |
amount(0.5) |
0,5 |
amount(1.5, :minimum_precision => 2) |
1,50 |
amount(1.543, :minimum_precision => 2) |
1,543 |
amount(1.5, :minimum_precision => 2, :separator => '.') |
1.50 |
amount(nil) |
– |
If your amounts are Western hemisphere money amounts, you want some additional prettifications on top of that:
A second helper method in the attached file does just that. Some usage examples with their resulting strings:
Invocation | Result |
---|---|
money_amount(0) |
0,00 € |
money_amount(0.0) |
0,00 € |
money_amount(0.5) |
0,50 € |
money_amount(1.543) |
1,543 € |
money_amount(0.5, :unit => '₣') |
0,50 ₣ |
money_amount(nil) |
– |