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

前端 未结 14 2001
小鲜肉
小鲜肉 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条回答
  •  遥遥无期
    2020-12-07 09:03

    You want the number_with_delimiter method. For example:

    <%= number_with_delimiter(@number, :delimiter => ',') %>
    

    Alternatively, you can use the number_with_precision method to ensure that the number is always displayed with two decimal places of precision:

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

提交回复
热议问题