Converts a fraction to a formatted percentage.

    :param value: number
    :param digits: default ``2``

    >>> print(percentage(1))
    100.00 %
    >>> print(percentage(0.23, digits=0))
    23 %
    >>> print(percentage(23.421))
    2,342.10 %
505403
def percentage(value, digits=2):
    '''
    

    '''

    value = float(value) * 100.0
    return u'' + '%s %%' % (_format(value, digits),)
519523
def rounddown(ctx, number, num_digits):
    
    number = conversions.to_decimal(number, ctx)
    num_digits = conversions.to_integer(num_digits, ctx)

    return decimal_round(number, num_digits, ROUND_DOWN)
41270
def _precision(self, value):
        
        value = str(value)
        decimal = value.rfind('.')
        if decimal == -1:
            return 0
        return len(value) - decimal - 1
669939
def real_value(value, digit):
    
    return str(float(value) / math.pow(10, float(digit)))
1204806
def _print_percent(self):
        ''''''
        fraction_done = ((self.continue_value or 0 + self.current_value) /
                         self.max_value)

        self._print('{fraction_done:.1%}'.format(fraction_done=fraction_done))
1275291
def round_to_fraction(val, res, decimals=None):
    
    if val is None:
        return 0.0
    if decimals is None and "." in str(res):
        decimals = len(str(res).split('.')[1])

    return round(round(val / res) * res, decimals)
462508
def roundup(ctx, number, num_digits):
    
    number = conversions.to_decimal(number, ctx)
    num_digits = conversions.to_integer(num_digits, ctx)

    return decimal_round(number, num_digits, ROUND_UP)
275466
function round(value, digits)
{
    if (! digits) { digits = 0; }
    var scale = Math.pow(10, digits);
    return Math.round(value * scale) / scale;
}
1285808
def format_decimal(decimal):
    
    # strip trailing fractional zeros
    normalized = decimal.normalize()
    sign, digits, exponent = normalized.as_tuple()
    if exponent >= 1:
        normalized = normalized.quantize(1)

    return str(normalized)
901473
private String getPercentFormatted(final Integer value)
	{
		final Integer val = checkQuietly(getName(), value);
		return NumberFormat.getPercentInstance().format((double)val / 100);
	}
508157
def fraction_digits(n: Literal) -> Optional[int]:
    
    # Note - the last expression below isolates the fractional portion, reverses it (e.g. 017320 --> 023710) and
    #        converts it to an integer and back to a string
    return None if not is_numeric(n) or n.value is None \
        else 0 if is_integer(n) or '.' not in str(n.value) or str(n.value).split('.')[1] == '0' \
        else len(str(int(str(n.value).split('.')[1][::-1])))
522356
def round_to_x_digits(number, digits):
    
    return round(number * math.pow(10, digits)) / math.pow(10, digits)
369275
def print_number_str(self, value, justify_right=True):
        
        # Calculate length of value without decimals.
        length = len(value.translate(None, '.'))
        # Error if value without decimals is longer than 4 characters.
        if length > 4:
            self.print_str('----')
            return
        # Calculcate starting position of digits based on justification.
        pos = (4-length) if justify_right else 0
        # Go through each character and print it on the display.
        for i, ch in enumerate(value):
            if ch == '.':
                # Print decimal points on the previous digit.
                self.set_decimal(pos-1, True)
            else:
                self.set_digit(pos, ch)
                pos += 1
109653
def as_percent(self, percent):
        
        if not self:
            return self.wrap_str()

        length = len(self)
        # Using mod 100, to provide some kind of "auto reset". 0 is 0 though.
        percentmod = (int(percent) % 100) or min(percent, 100)
        index = int((length / 100) * percentmod)
        try:
            barstr = str(self[index])
        except IndexError:
            barstr = self[-1]

        return self.wrap_str(barstr)
558798
def format_value(value):
    
    value = decimal.Decimal(str(value))
    if int(value) == value:
        return int(value)

    # On Python 3, an explicit cast to float is required
    return float(round(value, 1))
537978
def _assert_is_percentage(value, maximum=100):
    

    if value < 0 or value > maximum:
        message = 'The value on a percentage field should be between 0 and %s' \
                  % maximum
        raise pp.ParseException(message)
1293872
def formatPercent( value, options = nil )
      if value
         percent = (value.to_f * 100)
         value = percent.to_s
         if value.include?(".")
            int,fraction = value.split('.')
            if fraction.to_i == 0
               value = int
            else
               value = "#{int}.#{fraction[0,2]}"
            end            
         end         
      else
         value = "0"
      end
      value
   end