code: function(num, dec, tsep, dsep) {
          dec = (typeof dec != "undefined") ? dec : 0; 
          tsep = (typeof tsep != "undefined") ? tsep :
              OpenLayers.Number.thousandsSeparator; 
          dsep = (typeof dsep != "undefined") ? dsep :
              OpenLayers.Number.decimalSeparator;
  
          if (dec != null) {
              num = parseFloat(num.toFixed(dec));
          }
  
          var parts = num.toString().split(".");
          if (parts.length == 1 && dec == null) {
              // integer where we do not want to touch the decimals
              dec = 0;
          }
          
          var integer = parts[0];
          if (tsep) {
              var thousands = /(-?[0-9]+)([0-9]{3})/; 
              while(thousands.test(integer)) { 
                  integer = integer.replace(thousands, "$1" + tsep + "$2"); 
              }
          }
          
          var str;
          if (dec == 0) {
              str = integer;
          } else {
              var rem = parts.length > 1 ? parts[1] : "0";
              if (dec != null) {
                  rem = rem + new Array(dec - rem.length + 1).join("0");
              }
              str = integer + dsep + rem;
          }
          return str;
      }
docs: APIFunction: format
  Formats a number for output.
  
  Parameters:
  num  - {Float}
  dec  - {Integer} Number of decimal places to round to.
  Defaults to 0. Set to null to leave decimal places unchanged.
  tsep - {String} Thousands separator.
  Default is ",".
  dsep - {String} Decimal separator.
  Default is ".".
  
  Returns:
  {String} A string representing the formatted number.