<s> from django import template <EOL> from django . template . defaultfilters import stringfilter <EOL> import locale <EOL> register = template . Library ( ) <EOL> @ register . filter <EOL> @ stringfilter <EOL> def num_format ( value , places = <NUM_LIT:2> , min_places = <NUM_LIT:2> ) : <EOL> return format ( value , '<STR_LIT:.>' , int ( places ) , <NUM_LIT:3> , '<STR_LIT:U+002C>' , int ( min_places ) ) <EOL> @ register . filter <EOL> @ stringfilter <EOL> def sign_choice ( value , args = '<STR_LIT>' ) : <EOL> positive , negative , zero = args . split ( '<STR_LIT:U+002C>' ) <EOL> value = float ( value ) <EOL> if value == <NUM_LIT:0> : <EOL> return zero <EOL> elif value > <NUM_LIT:0> : <EOL> return positive <EOL> else : <EOL> return negative <EOL> @ register . filter <EOL> def sorted_set ( value ) : <EOL> return sorted ( value ) <EOL> def format ( number , decimal_sep , decimal_pos , grouping = <NUM_LIT:0> , thousand_sep = '<STR_LIT>' , min_decimal_pos = None ) : <EOL> """<STR_LIT>""" <EOL> if float ( number ) < <NUM_LIT:0> : <EOL> sign = '<STR_LIT:->' <EOL> else : <EOL> sign = '<STR_LIT>' <EOL> str_number = unicode ( "<STR_LIT>" % float ( 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 min_decimal_pos : <EOL> dec_part = dec_part + ( '<STR_LIT:0>' * ( min_decimal_pos - len ( dec_part ) ) ) <EOL> if dec_part : dec_part = decimal_sep + dec_part <EOL> if thousand_sep != '<STR_LIT>' and 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>
