// JavaScript Document
function format (expr, decplaces)
{
// raise incoming value by power of 10 time the number of decimal places; round to an integer; convert to string
var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
// pad small value strings with zeros to the left of rounded number
while (str.length <= decplaces)
{
str = "0" + str
}
// establish location of decimal point
var decpoint = str.length - decplaces
// determine the number of preceding spaces

if (str.length - 2 ==1)
  precspace= "&nbsp;";
 else if (str.length - 2 == 2)
  precspace = "";
// assemble final result from (a) the string up to the position of the decimal point;
// (b) the decimal point; and (c) the balance of the string.
//  Return finished product.
return precspace + str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

function formatnum (expr, decplaces)
{
// raise incoming value by power of 10 time the number of decimal places; round to an integer; convert to string
var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
// pad small value strings with zeros to the left of rounded number
while (str.length <= decplaces)
{
str = "0" + str
}
// establish location of decimal point
var decpoint = str.length - decplaces

// assemble final result from (a) the string up to the position of the decimal point;
// (b) the decimal point; and (c) the balance of the string.
//  Return finished product.
return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

//turn incoming expression into a dollar value
function dollarize (expr)
{  return "$"  + format(expr,2) }