您的位置:首页 > 大数据 > 人工智能

rails number_to_currency将数字转换为当前区域下的货币表示

2013-08-02 11:20 281 查看
number_to_currency(number, options = {})

Link

Instance Public methods

Formats a
number
into a currency string (e.g., $13.65). Youcan customize the format in the
options
hash.

Options

:locale
- Sets the locale to be used for formatting (defaultsto current locale).

:precision
- Sets the level of precision (defaults to 2).

:unit
- Sets the denomination of the currency (defaults to"$").

:separator
- Sets the separator between the units (defaults to".").

:delimiter
- Sets the thousands delimiter (defaults to ",").

:format
- Sets the format for non-negative numbers (defaultsto "%u%n"). Fields are
%u
for the currency, and
%n
for the number.

:negative_format
- Sets the format for negative numbers(defaults to prepending an hyphen to the formatted number given by
:format
). Accepts the same fields than
:format
,except
%n
is here the absolute value of the number.

Examples

number_to_currency(1234567890.50)                # => $1,234,567,890.50
number_to_currency(1234567890.506)               # => $1,234,567,890.51
number_to_currency(1234567890.506, precision: 3) # => $1,234,567,890.506
number_to_currency(1234567890.506, locale: :fr)  # => 1 234 567 890,51 €
number_to_currency('123a456')                    # => $123a456

number_to_currency(-1234567890.50, negative_format: '(%u%n)')
# => ($1,234,567,890.50)
number_to_currency(1234567890.50, unit: '£', separator: ',', delimiter: '')
# => £1234567890,50
number_to_currency(1234567890.50, unit: '£', separator: ',', delimiter: '', format: '%n %u')
# => 1234567890,50 £
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐