rails number_to_currency将数字转换为当前区域下的货币表示
2013-08-02 11:20
281 查看
number_to_currency(number, options = {})
Link
Instance Public methods
Formats a
Link
Instance Public methods
Formats a
numberinto a currency string (e.g., $13.65). Youcan customize the format in the
optionshash.
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
%ufor the currency, and
%nfor 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
%nis 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 £
相关文章推荐
- 一道面试题(把数字货币表示转换为大写表示,如把123.45转换为壹百贰拾叁元肆角伍分 )
- 把数字转换成中文货币表示
- CONVERT_TO_LOCAL_CURRENCY(货币汇率转换) 按日期取汇率
- 将阿拉伯数字表示的货币数值转换成以中文大写表示的货币数值
- 把数字转换成中文货币表示
- Magento 获取当前货币和货币符How to get current currency in Magento
- Format 根据当前区域文化来显示带有货币符号的数字。
- CONVERT_TO_LOCAL_CURRENCY(货币汇率转换)
- 将Excel的列数以字母表示的字符串转换成数字表示
- 阿拉伯数字转换英文数字表示算法解析及其实现
- 如何在Excel或sqlserver中写用户函数实现数字货币向英文转换集锦
- 任何国家都无法限制数字货币。为什么呢? 要想明白这个问题需要具备一点区块链的基础知识: 区块链使用的大致技术包括以下几种: a.点对点网络设计 b.加密技术应用 c.分布式算法的实现 d.数据存储技术 e.拜占庭算法 f.权益证明POW,POS,DPOS 原因一: 点对点网络设计 其中点对点的P2P网络是bittorent ,由于是点对点的网络,没有中心化,因此在全球分布式的网
- java中把数字转换为货币格式的方法及保留数位的问题
- 将数字转换成千分位表示
- ABAP--如何进行sap的金额数据存储和显示之间的转换(CURRENCY_AMOUNT_DISPLAY_TO_SAP)
- C# 数字货币转换大写方法
- leetcode 12 Integer to Roman(整型数转换为罗马数字)
- leetcode 273. Integer to English Words 阿拉伯数字转换为英文表示
- Android工具类——NumberUtils把数字字符串转换成指定国家的货币类型