📜  rails print number with space - Ruby 代码示例

📅  最后修改于: 2022-03-11 15:04:47.187000             🧑  作者: Mango

代码示例1
number.to_s.reverse.scan(/\d{1,3}/).join(",").reverse

number            #=> 12345678
.to_s             #=> "12345678"
.reverse          #=> "87654321"
.scan(/\d{1,3}/)  #=> ["876","543","21"]
.join(",")        #=> "876,543,21"
.reverse          #=> "12,345,678"