Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8172 (new defect)

Opened 1 year ago

Last modified 5 months ago

[PATCH] fix/enhance number_to_currency for negative numbers

Reported by: bgreenlee Assigned to:
Priority: low Milestone: 2.x
Component: ActionPack Version: edge
Severity: minor Keywords:
Cc:

Description

number_to_currency currently formats negative numbers incorrectly, putting the unit outside of the minus sign (e.g. "$-50"). This patch includes a fix to put the unit inside the minus sign ("-$50"), and adds a negative_parens option to output negative numbers in parentheses, as is common in accounting (e.g. number_to_currency(-50, :negative_parens => true) => "($50)")

Attachments

number_to_currency_fix_for_negative_numbers.diff (3.0 kB) - added by bgreenlee on 05/09/07 02:27:44.

Change History

04/26/07 01:43:00 changed by bgreenlee

  • owner changed from core to bgreenlee.
  • status changed from new to assigned.

04/26/07 01:48:30 changed by bgreenlee

oops, didn't mean to assign it...doesn't look like there's a way to unassign?

04/26/07 01:51:36 changed by bgreenlee

  • owner deleted.
  • status changed from assigned to new.

05/09/07 02:27:44 changed by bgreenlee

  • attachment number_to_currency_fix_for_negative_numbers.diff added.

05/09/07 02:30:17 changed by bgreenlee

fixed bug that affected negative numbers 0 > n > -1. Added tests.

07/02/07 02:24:59 changed by bgreenlee

Further research shows that the placement of the minus sign relative to the currency symbol (not to mention the placement of the currency symbol itself), is locale-specific. See http://www.microsoft.com/globaldev/getWR/steps/wrg_crncy.mspx. I'm not sure the best way to handle this. I think the ideal is to have Java-style localization support in Rails, but given that that's probably not happening anytime soon, perhaps a :format parameter that lets you specify, via a format string, the relative placement of everything. Some examples:

"$-x" "($x)" "€ x-"

Other suggestions?

02/18/08 12:28:54 changed by lylo

I think the format option is the way to go.

One issue I'm currently having is with Czeck Koruna, the symbol of which is Kč and appears after the value, e.g. 200 Kč. At the moment you can't render this using number_to_currency.

How about something like:

:format => '%s %f'

Where %s is the symbol and %f is the value, the default being %s%f.