A easy way to do data formatting in Javascript
Find system.js in the directory of AJAX WebShop and you will get these functions below:
-------Start----------
function FormatFloat(value,mask)
{
return BasicFormat(value,mask,'FormatNumber')
}
function FormatDate(varDate, bstrFormat, varDestLocale)
{
return BasicFormat(varDate,bstrFormat,'FormatDate',varDestLocale);
}
function FormatTime(varTime, bstrFormat, varDestLocale)
{
return BasicFormat(varTime,bstrFormat,'FormatTime',varDestLocale);
}
function BasicFormat(value,mask,action,param)
{
var xmlDoc;
var xslDoc;
var v='<formats><format><value>'+value+'</value><mask>'+mask+'</mask></format></formats>';
xmlDoc=parseXML(v);
var x;
if(isIE)
x='<xsl:stylesheet xmlns:xsl="uri:xsl">'
else
x='<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">';
x+='<xsl:template match="/">';
if(isIE) {
x+='<xsl:eval>'+action+'('+value+',"'+mask+'"';
if(param)x+=','+param;
x+=')</xsl:eval>';
}
else
x+='<xsl:value-of select="format-number('+value+',\''+mask+'\')" />';
x+='</xsl:template></xsl:stylesheet>';
xslDoc=parseXML(x);
var s;
if(isIE)
s= xmlDoc.transformNode(xslDoc)
else{
//for mozilla/netscape
var processor = new XSLTProcessor();
processor.importStylesheet(xslDoc);
var result = processor.transformToFragment(xmlDoc, xmlDoc);
var xmls = new XMLSerializer();
s = xmls.serializeToString(result);
}
return s;
}
---------End------------

