num.rb
require "active_support/core_ext/numeric/conversions"
10000.to_s(:delimited)
# => "10,000"
Details can be found on the Active Support page of the Rails Guide (6.3 Formatting) https://railsguides.jp/active_support_core_extensions.html#%E6%9B%B8%E5%BC%8F%E8%A8%AD%E5%AE%9A
When I was looking for a 3-digit display method "It seems that the .to_s (: delimited) method can be used to separate numbers into 3 digits!" I didn't know that require was needed and encountered the following error.
in `to_s': no implicit conversion of Symbol into Integer (TypeError)
I can use to_s normally, but when I add (: delimited), I get an error and am in trouble. Therefore, if you use the to_s (: delimited) method with ruby, you must require to enable active_support.
I would like to take this opportunity to learn and utilize other useful methods of active_support.
Recommended Posts