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

前端 未结 14 1994
小鲜肉
小鲜肉 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:13

    new syntax

    number_with_delimeter(@number, delimeter: ",")
    

    If you you want to user delimeter for money then you can do

    number_to_currency(@number)
    

    this will add $ too. If you are using money gem then you can do

    Money.new(@number,"USD").format
    

    This will also put $.

    number_with_delimiter

    ruby money

    number_to_currency

提交回复
热议问题