Module: Hanami::View::Helpers::NumberFormattingHelper
- Extended by:
- NumberFormattingHelper
- Included in:
- NumberFormattingHelper
- Defined in:
- lib/hanami/view/helpers/number_formatting_helper.rb
Overview
Helper methods for formatting numbers as text.
When using full Hanami apps, these helpers will be automatically available in your view templates, part classes and scope classes.
When using hanami-view standalone, include this module directly in your base part and scope classes, or in specific classes as required.
Defined Under Namespace
Classes: Formatter
Instance Method Summary collapse
-
#format_number(number, delimiter: DEFAULT_DELIMITER, separator: DEFAULT_SEPARATOR, precision: DEFAULT_PRECISION) ⇒ String
Returns a formatted string for the given number.
Instance Method Details
#format_number(number, delimiter: DEFAULT_DELIMITER, separator: DEFAULT_SEPARATOR, precision: DEFAULT_PRECISION) ⇒ String
Returns a formatted string for the given number.
Accepts a number (‘Numeric`) or a string representation of a number.
If an integer is given, applies no precision in the returned string. For all other kinds (‘Float`, `BigDecimal`, etc.), formats the number as a float.
Raises an ‘ArgumentError` if the argument cannot be coerced into a number for formatting.
86 87 88 |
# File 'lib/hanami/view/helpers/number_formatting_helper.rb', line 86 def format_number(number, delimiter: DEFAULT_DELIMITER, separator: DEFAULT_SEPARATOR, precision: DEFAULT_PRECISION) # rubocop:disable Layout/LineLength Formatter.call(number, delimiter: delimiter, separator: separator, precision: precision) end |