nodes: 0, module; 1, function_definition; 2, function_name:format_float; 3, parameters; 4, block; 5, identifier:x; 6, identifier:max_width; 7, expression_statement; 8, comment:# width of (whole part + 1 (to avoid zero)) + 1 because int floors, not ceils; 9, expression_statement; 10, comment:# for +/- sign; 11, expression_statement; 12, comment:# for . if we show it; 13, expression_statement; 14, return_statement; 15, string; 16, assignment; 17, assignment; 18, assignment; 19, binary_operator:'%.*f' % (max_width - whole_width - sign_width - decimal_point_width, x); 20, string_content:format_float will ensure that a number's decimal part is truncated to
      fit within some bounds, unless the whole part is wider than max_width,
      which is a problem you need to sort out yourself.; 21, identifier:whole_width; 22, binary_operator:int(math.log10(abs(x) + 1)) + 1; 23, identifier:sign_width; 24, conditional_expression:1 if x < 0 else 0; 25, identifier:decimal_point_width; 26, conditional_expression:1 if max_width >= whole_width else 0; 27, string; 28, tuple; 29, call; 30, integer:1; 31, integer:1; 32, comparison_operator:x < 0; 33, integer:0; 34, integer:1; 35, comparison_operator:max_width >= whole_width; 36, integer:0; 37, string_content:%.*f; 38, binary_operator:max_width - whole_width - sign_width - decimal_point_width; 39, identifier:x; 40, identifier:int; 41, argument_list; 42, identifier:x; 43, integer:0; 44, identifier:max_width; 45, identifier:whole_width; 46, binary_operator:max_width - whole_width - sign_width; 47, identifier:decimal_point_width; 48, call; 49, binary_operator:max_width - whole_width; 50, identifier:sign_width; 51, attribute; 52, argument_list; 53, identifier:max_width; 54, identifier:whole_width; 55, identifier:math; 56, identifier:log10; 57, binary_operator:abs(x) + 1; 58, call; 59, integer:1; 60, identifier:abs; 61, argument_list; 62, identifier:x
code: def format_float(x, max_width):
      '''format_float will ensure that a number's decimal part is truncated to
      fit within some bounds, unless the whole part is wider than max_width,
      which is a problem you need to sort out yourself.
      '''
      # width of (whole part + 1 (to avoid zero)) + 1 because int floors, not ceils
      whole_width = int(math.log10(abs(x) + 1)) + 1
      # for +/- sign
      sign_width = 1 if x < 0 else 0
      # for . if we show it
      decimal_point_width = 1 if max_width >= whole_width else 0
      return '%.*f' % (max_width - whole_width - sign_width - decimal_point_width, x)