// moneystuff.js
//
// Created: 2006-07-07
// Author: Bob Barnes
//
// Description: Various javascript functions useful on pages which do 
//   things to do with money


// Turn a numeric value into a pretty format

function CurrencyFormat( theValue )
{
  var prefix="";
  var wd;

  wd="w";
  var tempnum = theValue;
  for ( i = 0; i < tempnum.length; i++ )
  {
    if ( tempnum.charAt(i) == "." )
    {
    wd="d";
    break;
    }
  }
  
  if ( wd == "w" )
    {
    result = prefix+tempnum+".00";
    }
  else
  {
    if ( tempnum.charAt(tempnum.length-2) == "." )
    {
      result = prefix + tempnum + "0";
    }
    else
    {
      tempnum = Math.round( tempnum*100 ) / 100;
      result = prefix + tempnum;
    }
  }
  
  return( result );
}




<!-- Original:  Cyanide_7 (leo7278@hotmail.com) -->
<!-- Web Site:  http://www7.ewebcity.com/cyanide7 -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

// Changed by BoB to work with pounds, and silently remove a pound sign
//    if it is entered

<!-- Begin
function formatCurrency(num) {
num = num.toString().replace(/\£|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + num + '.' + cents);
}
//  End -->
