Format a unit value.
198742
public void formatUnit(UnitValue value, StringBuilder destination, UnitFormatOptions options) {
    BigDecimal n = value.amount();
    boolean grouping = orDefault(options.grouping(), false);
    NumberFormatContext ctx = new NumberFormatContext(options, NumberFormatMode.DEFAULT);
    NumberPattern numberPattern = select(n, unitStandard);
    ctx.set(numberPattern);

    BigDecimal q = ctx.adjust(n);
    NumberOperands operands = new NumberOperands(q.toPlainString());
    PluralCategory category = PLURAL_RULES.evalCardinal(bundleId.language(), operands);
    
    Unit unit = value.unit();
    List<FieldPattern.Node> unitPattern = null;
    
    // We allow unit to be null to accomodate the caller as a last resort.
    // If the unit is not available we still format a number.
    if (unit != null) {
      switch (options.format()) {
        case LONG:
          unitPattern = getPattern_UNITS_LONG(unit, category);
          break;
          
        case NARROW:
          unitPattern = getPattern_UNITS_NARROW(unit, category);
          break;
          
        case SHORT:
        default:
          unitPattern = getPattern_UNITS_SHORT(unit, category);
          break;
      }
    }
    
    DigitBuffer number = new DigitBuffer();
    NumberFormattingUtils.format(q, number, params, false, grouping, ctx.minIntDigits(), 
        numberPattern.format.primaryGroupingSize(), 
        numberPattern.format.secondaryGroupingSize());

    if (unitPattern == null) {
      number.appendTo(destination);
      
    } else {
      DigitBuffer dbuf = new DigitBuffer();
      for (FieldPattern.Node node : unitPattern) {
        if (node instanceof FieldPattern.Text) {
          dbuf.append(((FieldPattern.Text)node).text());
          
        } else if (node instanceof Field) {
          Field field = (Field)node;
          if (field.ch() == '0') {
            format(numberPattern, number, dbuf, null, null);
          }
        }
      }
      dbuf.appendTo(destination);
    }
  }
1038519
String formatUnits(int units) {
		switch (unitType) {
			case ENGLISH:
				return NumberFormat.getDecimalFormat().format(units) + (widthInUnitsIsMiles ? " mi" : " yd");
			case ENGLISH_FOOT:
				return NumberFormat.getDecimalFormat().format(units) + (widthInUnitsIsMiles ? " mi" : " ft");
			case METRIC:
				if (units < 10000) {
					return NumberFormat.getDecimalFormat().format(units) + " m";
				} else {
					return NumberFormat.getDecimalFormat().format((double) units / 1000) + " km";
				}

			case CRS:
				return NumberFormat.getDecimalFormat().format(units) + " u";

			default:
				throw new IllegalStateException("Unknown unit type " + unitType);
		}
	}
1183047
def format_value(self, value, padding):
        """"""

        # padding = padding - 1 if value < 0 and padding > 0 else padding
        # prefix = '-' if value < 0 else ''

        if padding:
            return "{:0{pad}d}".format(value, pad=padding)

        else:
            return str(value)
949071
def format_units(v, step=None, system="si", units=None):
    
    if v is None:
        return 0, ''

    for prefix, size in UnitSystems[system]:
        if condition(v, size, step):
            v2 = v / size
            if v2 - math.floor(v2) < 0.00000000001 and v > 1:
                v2 = float(math.floor(v2))
            if units:
                prefix = "%s%s" % (prefix, units)
            return v2, prefix

    if v - math.floor(v) < 0.00000000001 and v > 1:
        v = float(math.floor(v))
    if units:
        prefix = units
    else:
        prefix = ''
    return v, prefix
1198536
def normalize(value, unit):
    
    if value < 0:
        raise ValueError('Negative value: %s %s.' % (value, unit))

    if unit in functions.get_keys(INFORMATION_UNITS):
        return _normalize_information(value, unit)
    elif unit in TIME_UNITS:
        return _normalize_time(value, unit)
    else:
        # Unknown unit, just return it
        return functions.format_value(value), unit
767987
def _value_format(self, value):
        """"""
        return super(Funnel, self)._value_format(value and abs(value))
606206
def _serie_format(self, serie, value):
        """"""

        kwargs = {'chart': self, 'serie': serie, 'index': None}
        formatter = (serie.formatter or self.formatter or self._value_format)
        kwargs = filter_kwargs(formatter, kwargs)
        return formatter(value, **kwargs)
527359
def _format_value(self, value):
        
        if len(value) > 0:
            if value[0] == ".":
                value = self.package + value
            else:
                v_dot = value.find(".")
                if v_dot == 0:
                    value = self.package + "." + value
                elif v_dot == -1:
                    value = self.package + "." + value
        return value
1226244
def float_format(self, value):
        """"""
        if isinstance(value, str):
            # Duck-test the format string; raise ValueError on fail
            '{0:{1}}'.format(1.23, value)

            self._float_format = value
        else:
            raise TypeError('Floating point format code must be a string.')
680418
def format_num(num, unit='bytes'):
    
    if unit == 'bytes':
        extension = 'B'
    else:
        # if it's not bytes, it's bits
        extension = 'Bit'
    for dimension in (unit, 'K', 'M', 'G', 'T'):
        if num < 1024:
            if dimension == unit:
                return '%3.1f %s' % (num, dimension)
            return '%3.1f %s%s' % (num, dimension, extension)
        num /= 1024
    return '%3.1f P%s' % (num, extension)
760875
def format(self):
        """"""
        value = self._schema.get("format", None)
        if value is None:
            return
        if not isinstance(value, basestring):
            raise SchemaError(
                "format value {0!r} is not a string".format(value))
        if value in [
            'date-time',
            'regex',
        ]:
            return value
        raise NotImplementedError(
            "format value {0!r} is not supported".format(value))
1067171
public static void formatLongitude(Appendable out, Locale locale, double longitude, UnitType unit)
    {
        format(out, locale, longitude, unit, EW);
    }
52958
def _FormatSizeInUnitsOf1024(self, size):
    
    magnitude_1024 = 0
    used_memory_1024 = float(size)
    while used_memory_1024 >= 1024:
      used_memory_1024 /= 1024
      magnitude_1024 += 1

    if 0 < magnitude_1024 <= 7:
      return '{0:.1f} {1:s}'.format(
          used_memory_1024, self._UNITS_1024[magnitude_1024])

    return '{0:d} B'.format(size)
1325531
def to_unit(self, unit):
        """"""
        new_data_c = self.duplicate()
        new_data_c.convert_to_unit(unit)
        return new_data_c
712913
def format_value(self, val):
        """"""
        if isinstance(val, six.text_type):
            return self.format_string(val)
        else:
            return six.text_type(val)
405025
private String formatTimeUnit(TimeUnit timeUnit)
   {
      int units = timeUnit.getValue();
      String result;
      String[][] unitNames = LocaleData.getStringArrays(m_locale, LocaleData.TIME_UNITS_ARRAY);

      if (units < 0 || units >= unitNames.length)
      {
         result = "";
      }
      else
      {
         result = unitNames[units][0];
      }

      return (result);
   }
884225
def to_unit(self, values, unit, from_unit):
        """"""
        return self._to_unit_base('degC-days', values, unit, from_unit)