Module: Padrino::Helpers::NumberHelpers
Overview
Provides methods for converting numbers into formatted strings. Methods are provided for phone numbers, currency, percentage, precision, positional notation, and file size.
Adapted from Rails Number Helpers.
Constant Summary collapse
- STORAGE_UNITS =
The units available for storage formatting.
[:byte, :kb, :mb, :gb, :tb].freeze
Instance Method Summary
-
#number_to_currency(number, options = {}) ⇒ StringFormats anumberinto a currency string (e.g., $13.65). -
#number_to_human_size(number, options = {}) ⇒ StringFormats the bytes insizeinto a more understandable representation (e.g., giving it 1500 yields 1.5 KB). -
#number_to_percentage(number, options = {}) ⇒ StringFormats anumberas a percentage string (e.g., 65%). -
#number_with_delimiter(number, options = {}) ⇒ StringFormats anumberwith grouped thousands usingdelimiter(e.g., 12,324). -
#number_with_precision(number, options = {}) ⇒ StringFormats anumberwith the specified level of:precision(e.g., 112.32 has a precision of 2).
Instance Method Details
#number_to_currency(number, options = {}) ⇒ String
Formats a number into a currency string (e.g., $13.65). You can customize the format in the options hash.
#number_to_human_size(number, options = {}) ⇒ String
Formats the bytes in size into a more understandable representation (e.g., giving it 1500 yields 1.5 KB). This method is useful for reporting file sizes to users. This method returns nil if size cannot be converted into a number. You can customize the format in the options hash.
#number_to_percentage(number, options = {}) ⇒ String
Formats a number as a percentage string (e.g., 65%). You can customize the format in the options hash.
#number_with_delimiter(number, options = {}) ⇒ String
Formats a number with grouped thousands using delimiter (e.g., 12,324). You can customize the format in the options hash.
#number_with_precision(number, options = {}) ⇒ String
Formats a number with the specified level of :precision (e.g., 112.32 has a precision of 2). You can customize the format in the options hash.
© 2010–2020 Padrino
Licensed under the MIT License.
https://www.rubydoc.info/github/padrino/padrino-framework/Padrino/Helpers/NumberHelpers