Nếu test trong rails c trước tiên phải include ActionView::Helpers::NumberHelper
ActionView::Helpers::NumberHelper của Rails có nhiều hàm hoạt động với con số
- number_to_currency → chuyển số sang dạng $
number_to_currency(1200.5) # => $1,200.5
- number_to_human → chuyển số lớn sang dạng chữ tiếng anh
number_to_human(1900) # => 1.9 million
number_to_human(1900, unit: {thousand: 'nghin') # => 1.9 nghin
- number_to_percentage → chuyển số sang dạng %
number_to_percentage(29.876543, precision: 3) # => 29.876% number_to_percentage('20a') # => 20a% number_to_percentage('20a', raise: true) # => InvalidNumberError
- number-to-phone → chuyển số thành dạng số điện thoại
number_to_phone('09897776') # => 098-977-76
number_to_phone('09897776', delimiter: ' ') # => 098 977 76
number_to_phone(9897776, country_code: 84, delimiter: ' ') # => +84 989 7776