def floatformat(text, arg=(-1)):
 try:
  input_val = force_unicode(text)
  d = Decimal(input_val)
 except UnicodeEncodeError:
  return u''
 except InvalidOperation:
  if (input_val in special_floats):
   return input_val
  try:
   d = Decimal(force_unicode(float(text)))
  except (ValueError, InvalidOperation, TypeError, UnicodeEncodeError):
   return u''
 try:
  p = int(arg)
 except ValueError:
  return input_val
 try:
  m = (int(d) - d)
 except (ValueError, OverflowError, InvalidOperation):
  return input_val
 if ((not m) and (p < 0)):
  return mark_safe(formats.number_format((u'%d' % int(d)), 0))
 if (p == 0):
  exp = Decimal(1)
 else:
  exp = (Decimal('1.0') / (Decimal(10) ** abs(p)))
 try:
  return mark_safe(formats.number_format((u'%s' % str(d.quantize(exp, ROUND_HALF_UP))), abs(p)))
 except InvalidOperation:
  return input_val

def floatformat ( text , arg = ( - 1 ) ) : try : input_val = force_unicode ( text ) d = Decimal ( input_val ) except UnicodeEncodeError : return u'' except InvalidOperation : if ( input_val in special_floats ) : return input_val try : d = Decimal ( force_unicode ( float ( text ) ) ) except ( ValueError , InvalidOperation , TypeError , UnicodeEncodeError ) : return u'' try : p = int ( arg ) except ValueError : return input_val try : m = ( int ( d ) - d ) except ( ValueError , OverflowError , InvalidOperation ) : return input_val if ( ( not m ) and ( p < 0 ) ) : return mark_safe ( formats . number_format ( ( u'%d' % int ( d ) ) , 0 ) ) if ( p == 0 ) : exp = Decimal ( 1 ) else : exp = ( Decimal ( '1.0' ) / ( Decimal ( 10 ) ** abs ( p ) ) ) try : return mark_safe ( formats . number_format ( ( u'%s' % str ( d . quantize ( exp , ROUND_HALF_UP ) ) ) , abs ( p ) ) ) except InvalidOperation : return input_val
if called without an argument .