Rails如何根据印度的编号系统分隔号码?

How to separate a number according to the Indian numbering system in Rails?

我在 Rails 的 Ruby 中使用 number_with_delimiter 方法为发票中的数字添加逗号。但是数字格式导致 23,324,455 而不是 2,33,24,455,即 Indian Rupees format

<%= number_with_precision(@number, :precision => 2, :delimiter => ',') %>

我必须生成金额为卢比的发票,因此格式应为 xx,xx,xxx.00。 Rails 有可能吗?如何实现?

这可以用 JavaScript 完成,但问题是,我使用 PDFKit gem 生成了 PDF 格式的发票,但 JavaScript 没有响应。我在加载文档时使用了所需的js代码。

$(document).ready(function(){
  $('.totalvalue').each(function(){
    value = $('.totalvalue').text();
    $('.totalvalue').html(
      (value+"").split("").reverse().join("").replace(/(\d{3})(?=\d)/g,        ',').split("").reverse().join("")
    )
  })
})

不优雅,但有效:

("%.2f" % 23324455).reverse.gsub(/(?<=.{6})(\d\d?)/, ',').reverse
# => "2,33,24,455.00"

您可以使用 money gem, and specifically explore its formatting options.

Money.new(10000000, "INR").format(:symbol => false, 
                                  :south_asian_number_formatting => true)    
#=> "1,00,000.00"