<s> from airy . core . conf import settings <EOL> from airy . utils . safestring import mark_safe <EOL> def format ( number , decimal_sep , decimal_pos , grouping = <NUM_LIT:0> , thousand_sep = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> use_grouping = settings . USE_L10N and settings . USE_THOUSAND_SEPARATOR and grouping <EOL> if isinstance ( number , int ) and not use_grouping and not decimal_pos : <EOL> return mark_safe ( unicode ( number ) ) <EOL> if float ( number ) < <NUM_LIT:0> : <EOL> sign = '<STR_LIT:->' <EOL> else : <EOL> sign = '<STR_LIT>' <EOL> str_number = unicode ( number ) <EOL> if str_number [ <NUM_LIT:0> ] == '<STR_LIT:->' : <EOL> str_number = str_number [ <NUM_LIT:1> : ] <EOL> if '<STR_LIT:.>' in str_number : <EOL> int_part , dec_part = str_number . split ( '<STR_LIT:.>' ) <EOL> if decimal_pos : <EOL> dec_part = dec_part [ : decimal_pos ] <EOL> else : <EOL> int_part , dec_part = str_number , '<STR_LIT>' <EOL> if decimal_pos : <EOL> dec_part = dec_part + ( '<STR_LIT:0>' * ( decimal_pos - len ( dec_part ) ) ) <EOL> if dec_part : dec_part = decimal_sep + dec_part <EOL> if use_grouping : <EOL> int_part_gd = '<STR_LIT>' <EOL> for cnt , digit in enumerate ( int_part [ : : - <NUM_LIT:1> ] ) : <EOL> if cnt and not cnt % grouping : <EOL> int_part_gd += thousand_sep <EOL> int_part_gd += digit <EOL> int_part = int_part_gd [ : : - <NUM_LIT:1> ] <EOL> return sign + int_part + dec_part </s>
