Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何使用Rails编号到货币选项_Ruby On Rails_Currency - Fatal编程技术网

Ruby on rails 如何使用Rails编号到货币选项

Ruby on rails 如何使用Rails编号到货币选项,ruby-on-rails,currency,Ruby On Rails,Currency,我正在使用Rails,希望将浮动转换为货币。我在Sidekiq Worker中使用了number\u to\u currency,因此我在文件中添加了include ActionView::Helpers::NumberHelper,并在需要转换的位置添加了以下内容: number_to_currency(value, unit: '', delimeter: '.', separator: ',') 我想要的结果是:1.200,09,但它不起作用。我拥有并想要转换的值的一个例子是:1001.

我正在使用Rails,希望将浮动转换为货币。我在Sidekiq Worker中使用了
number\u to\u currency
,因此我在文件中添加了
include ActionView::Helpers::NumberHelper
,并在需要转换的位置添加了以下内容:

number_to_currency(value, unit: '', delimeter: '.', separator: ',')
我想要的结果是:
1.200,09
,但它不起作用。我拥有并想要转换的值的一个例子是:
1001.429000000004
,它应该转换为
1.001,43
。我也试过:

number_to_currency(final_total, unit: '', delimeter: ',', separator: '.')
但仍然不起作用。我得到的是
1200.09
。我使用的是Rails 4.2.x


我在这里遗漏了什么?

您只是在word
分隔符中输入了一个拼写错误。其内容应如下:

number_to_currency(value, unit: '', delimiter: '.', separator: ',')

如果您希望得到这样的结果
1001.429000000004=>1001.43
,可以使用以下方法:

number_with_delimiter(value , delimiter: ",", separator: ".")
但在您需要将
转换为所需值之前:

value = 1001.4290000000004.round(2) #=> 1001.43