src/misc/filters.js
function UnitPrefixFilter($filter) {
  const numberFilter = $filter('ngeoNumber');
  const standardPrefix = ['', 'k', 'M', 'G', 'T', 'P'];
  const binaryPrefix = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi'];
  /**
   * @param {number} number The number to format.
   * @param {string=} opt_unit The unit to used, default is ''.
   * @param {string=} opt_type (unit|square|binary) the type of units, default is 'unit'.
   * @param {number=} opt_precision The used precision, default is 3.
   * @return {string} The formatted string.
   */
  const result = function(number, opt_unit, opt_type, opt_precision) {
    if (opt_unit === undefined) {
      opt_unit = '';
    }
    let divisor = 1000;
    let prefix = standardPrefix;
    if (opt_type === 'square') {
      divisor = 1000000;
    } else if (opt_type === 'binary') {
      divisor = 1024;
      prefix = binaryPrefix;
    }

    let index = 0;
    const index_max = prefix.length - 1;
    while (number >= divisor && index < index_max) {
      number = number / divisor;
      index++;
    }

    const postfix = prefix[index] + opt_unit;
    const space = postfix.length == 0 ? '' : '\u00a0';
    return numberFilter(number, opt_precision) + space + postfix;
  };
  return result;
}
function UnitPrefixFilter($filter) {
  const numberFilter = $filter('ngeoNumber');
  const standardPrefix = ['', 'k', 'M', 'G', 'T', 'P'];
  const binaryPrefix = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi'];
  /**
   * @param {number} number The number to format.
   * @param {string=} opt_unit The unit to used, default is ''.
   * @param {string=} opt_type (unit|square|binary) the type of units, default is 'unit'.
   * @param {number=} opt_precision The used precision, default is 3.
   * @return {string} The formatted string.
   */
  const result = function(number, opt_unit, opt_type, opt_precision) {
    if (opt_unit === undefined) {
      opt_unit = '';
    }
    let divisor = 1000;
    let prefix = standardPrefix;
    if (opt_type === 'square') {
      divisor = 1000000;
    } else if (opt_type === 'binary') {
      divisor = 1024;
      prefix = binaryPrefix;
    }

    let index = 0;
    const index_max = prefix.length - 1;
    while (number >= divisor && index < index_max) {
      number = number / divisor;
      index++;
    }

    const postfix = prefix[index] + opt_unit;
    const space = postfix.length == 0 ? '' : '\u00a0';
    return numberFilter(number, opt_precision) + space + postfix;
  };
  return result;
}
function UnitPrefixFilter ( $filter ) { const numberFilter = $filter ( 'ngeoNumber' ) ; const standardPrefix = [ '' , 'k' , 'M' , 'G' , 'T' , 'P' ] ; const binaryPrefix = [ '' , 'Ki' , 'Mi' , 'Gi' , 'Ti' , 'Pi' ] ; /**
   * @param {number} number The number to format.
   * @param {string=} opt_unit The unit to used, default is ''.
   * @param {string=} opt_type (unit|square|binary) the type of units, default is 'unit'.
   * @param {number=} opt_precision The used precision, default is 3.
   * @return {string} The formatted string.
   */ const result = function ( number , opt_unit , opt_type , opt_precision ) { if ( opt_unit === undefined ) { opt_unit = '' ; } let divisor = 1000 ; let prefix = standardPrefix ; if ( opt_type === 'square' ) { divisor = 1000000 ; } else if ( opt_type === 'binary' ) { divisor = 1024 ; prefix = binaryPrefix ; } let index = 0 ; const index_max = prefix . length - 1 ; while ( number >= divisor && index < index_max ) { number = number / divisor ; index ++ ; } const postfix = prefix [ index ] + opt_unit ; const space = postfix . length == 0 ? '' : '\u00a0' ; return numberFilter ( number , opt_precision ) + space + postfix ; } ; return result ; }
A filter used to format a number with the prefix and unit

Arguments:
- opt_unit: The unit to used, default is ''.
- opt_type: (unit|square|binary) the type of units, default is 'unit'.
- opt_precision: The used precision, default is 3.

Examples:

{{25000 | ngeoUnitPrefix}} => 25 k
{{25000 | ngeoUnitPrefix:'m'}} => 25 km
{{25000000 | ngeoUnitPrefix:'m²':'square'}} => 25 km²
{{2048 | ngeoUnitPrefix:'o':'binary'}} => 2 Kio


@param {angular.IFilterService} $filter Angular filter
@return {unitPrefix} Function used to format number into a string.
@ngInject
@ngdoc filter
@ngname ngeoUnitPrefix
A filter used to format a number with the prefix and unit