#
# Clark Maskell 12/11/2000
# I wrote this subroutine to format numbers with commas
#

sub curr {

  local($val) = @_[0];
  local($precision) = @_[1];
  local($spot);
  local($move);
  local($final);
  local($mod);
  local($idx);


  $val =~ s/ //g;
  $fmt = "%.".$precision."f";
  $val = sprintf("$fmt",$val);
    
  $spot = index($val,".");


  if ($spot == -1) { $spot = length($val); }


  while ($spot - $move > 0) {
    $move = $move + 1;
    $final = substr($val, $spot - $move, 1).$final;
    $mod = $move % 3;
    if ($mod == 0 && $spot - $move != 0 && substr($val,$spot-$move-1,1) ne '-') { 
      $final = ",".$final; 
    }
  }


  $idx = index($val,".");
  if ($idx > 0) { 
    $sz = length($val);
    $final = $final.substr($val,$idx, $sz - $idx);
  }


  return($final);

 
} 


# Required or will cause errors (dont know why)
1;

