Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
22261405
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
22261405
编写于
1月 29, 2016
作者:
R
Rafael França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #23329 from prathamesh-sonpatki/fix-23320
Change number_to_currency behavior for checking negativity of a number
上级
4de09224
d3f178bb
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
16 addition
and
6 deletion
+16
-6
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+15
-0
activesupport/lib/active_support/number_helper/number_to_currency_converter.rb
...ive_support/number_helper/number_to_currency_converter.rb
+1
-5
activesupport/test/number_helper_test.rb
activesupport/test/number_helper_test.rb
+0
-1
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
22261405
*
Change number_to_currency behavior for checking negativity.
Used `to_f.negative` instead of using `to_f.phase` for checking negativity
of a number in number_to_currency helper.
This change works same for all cases except when number is "-0.0".
-0.0.to_f.negative? => false
-0.0.to_f.phase? => 3.14
This change reverts changes from https://github.com/rails/rails/pull/6512.
But it should be acceptable as we could not find any currency which
supports negative zeros.
*Prathamesh Sonpatki*, *Rafael Mendonça França*
*
Match
`HashWithIndifferentAccess#default`
's behaviour with
`Hash#default`
.
*David Cornu*
...
...
activesupport/lib/active_support/number_helper/number_to_currency_converter.rb
浏览文件 @
22261405
...
...
@@ -7,7 +7,7 @@ def convert
number
=
self
.
number
.
to_s
.
strip
format
=
options
[
:format
]
if
is_negative?
(
number
)
if
number
.
to_f
.
negative?
format
=
options
[
:negative_format
]
number
=
absolute_value
(
number
)
end
...
...
@@ -18,10 +18,6 @@ def convert
private
def
is_negative?
(
number
)
number
.
to_f
.
phase
!=
0
end
def
absolute_value
(
number
)
number
.
respond_to?
(
:abs
)
?
number
.
abs
:
number
.
sub
(
/\A-/
,
''
)
end
...
...
activesupport/test/number_helper_test.rb
浏览文件 @
22261405
...
...
@@ -74,7 +74,6 @@ def test_number_to_currency
assert_equal
(
"1,234,567,890.50 Kč"
,
number_helper
.
number_to_currency
(
"1234567890.50"
,
{
:unit
=>
"Kč"
,
:format
=>
"%n %u"
}))
assert_equal
(
"1,234,567,890.50 - Kč"
,
number_helper
.
number_to_currency
(
"-1234567890.50"
,
{
:unit
=>
"Kč"
,
:format
=>
"%n %u"
,
:negative_format
=>
"%n - %u"
}))
assert_equal
(
"0.00"
,
number_helper
.
number_to_currency
(
+
0.0
,
{
:unit
=>
""
,
:negative_format
=>
"(%n)"
}))
assert_equal
(
"(0.00)"
,
number_helper
.
number_to_currency
(
-
0.0
,
{
:unit
=>
""
,
:negative_format
=>
"(%n)"
}))
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录