Rails: Is there a rails trick to adding commas to large numbers?

前端 未结 14 2006
小鲜肉
小鲜肉 2020-12-07 08:19

Is there a way to have rails print out a number with commas in it?

For example, if I have a number 54000000.34, I can run <%= number.function %>, which would prin

14条回答
  •  Happy的楠姐
    2020-12-07 09:02

    The following do the trick for both delimiter and precision (API ref).

    ActiveSupport::NumberHelper.number_to_rounded(1234.532, delimiter: ',', precision: 1) 
    

    (or from views just number_to_rounded, no need for the suffix)

    HTH

提交回复
热议问题