You are here

function _range_number_format in Range 7

Helper function. Formats a number according to formatter settings.

Parameters

int|double $number: Number to format.

string $display_type: Formatter being used.

array $settings: Array of formatter settings:

  • format_string: format string for sprintf() function
  • scale: number scale
  • decimal_separator: string, used as a decimal separator
  • thousand_separator: string, used as a thousand separator.

Return value

string Formatted number.

3 calls to _range_number_format()
RangeUnitTestCase::testRangeNumberFormat in tests/range.unit.test
Tests range number formatter.
range_field_formatter_settings_summary in ./range.module
Implements hook_field_formatter_settings_summary().
range_field_formatter_view in ./range.module
Implements hook_field_formatter_view().

File

./range.module, line 498
Defines range field types.

Code

function _range_number_format($number, $display_type, array $settings) {
  switch ($display_type) {
    case 'range_integer':
    case 'range_decimal':
      return (string) number_format($number, $settings['scale'], $settings['decimal_separator'], $settings['thousand_separator']);
    case 'range_integer_sprintf':
    case 'range_decimal_sprintf':
      return (string) sprintf(field_filter_xss($settings['format_string']), $number);
    default:
      return (string) $number;
  }
}