小数点后显示零的问题

时间:2016-10-10 08:56:51

标签: csv jscript

我设置了一个脚本,用于将csv文件中的数字提取到网页中。我们遇到一个问题,即小数点后面有一个0的数字被忽略,所以当csv数据转移到网页时csv文件显示1.094时它是1.94

有一个js脚本,然后是一个运行该函数的asp脚本

        function getHTTPObject()
         {
          var x = null;
if (window.XMLHttpRequest)
{
  x = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
  x = new ActiveXObject("Microsoft.XMLHTTP");
  if (!x)
  {
  x = new ActiveXObject("Msxml2.XMLHTTP");
  }
}
return x;
         }

         var gobj = getHTTPObject();
         window.onload=update();
         function update()
         { 
          var xpath = "ratesxtract.asp";  
           if (gobj) {  
                   gobj.open("GET", xpath, true); 
                   gobj.onreadystatechange = update_all;
                   gobj.send(null);     
           }
         else {alert("XMLHTTP access problem. Please exit page and try            again" ); }
         }
         function update_all()
         {
        if (gobj.readyState == 4) {
     if (gobj.status == 200) {
       //           dobj = document.getElementById("BLastUpdated");
                 var A = gobj.responseText;
           //        dobj.innerHTML = A;
                    if (A == "error") {alert("XMLHTTP access problem. Please            exit page and contact us" ); }
                  else { processfile(A); }
           }
         }
         function processfile(A)
         {
           var errormess = "none";
           var AA = new String(A);
           AA = AA.split("$");  
              var nName = null;
                 var dobj = null;
                 var nValue = null;
                      var i = 0;     
           for (i = 0; i < AA.length; i++) {    
                           if (AA[i].charAt(0) == "Z") {       
                                                 nName = AA[i];
                                                 dobj =            document.getElementById(nName);
                                                 }
                           else  {  nValue = "";
                                    nValue += AA[i];
                                    dobj.innerHTML = nValue; 
                                    }
                     }     
           if ( i == 0 ) { errormess = "failed to access exchange rates data,            please exit page and try again";
                       alert(errormess)
                       }            
         }

  ASP SCRIPT 



<%@LANGUAGE='JScript'%>
<%
var sfile = Server.MapPath("forex\\ratefile.csv");
var fs = Server.CreateObject("Scripting.FileSystemObject");
var fsT = fs.OpenTextFile(sfile, 1, 0);
var xline;
var p = 0;
var q = 0;
var d = 0;
var i = 0;
var n = 0;
var t = 0;
var ts = 0;
var mname;
var mprice;
var mtime = "";
var INLine
var LN;
var cresult = "";
 while(!fsT.AtEndOfStream) {          
          INLine = fsT.ReadLine();
          xline = String(INLine);
          if ( p != 0) {
             LN = xline.split(",");
             mname = xtrim(LN[0]);
             mprice =  doamount3(LN[1]);
             if (p == 1) { mtime = xtrim(LN[2]); }            
             if (n > 0){ cresult += "$"; }
             n++;                  
             cresult += "Z" + mname + "$" + mprice;                
       }
        p++;
}
cresult += "$ZTIM$" + mtime;
fsT.Close();
Response.Write(cresult);
%>

<%
function xtrim(x)
{
var xd = x.replace(/^\s+|\s+$/gm,'');
return xd;
}
function doamount3(amt)
{
var ZLine = String(amt);
ZLine = xtrim(ZLine);
if (ZLine.indexOf(".") == -1) {
                      ZLine += ".00";
                      return(ZLine);
                      }

var idata = ZLine.split(".");
var xadp = new String(idata[1]);
var xlen = xadp.length;

if (xlen == 1) {
            idata[1] = xadp + "00";
            ZLine = idata[0] + "." + idata[1];
            return(ZLine);
           }
if (xlen == 2) {
            idata[1] = xadp + "0";
            ZLine = idata[0] + "." + idata[1];
            return(ZLine);
       }
var p4 = xadp.charAt(3);
var p3 = parseInt(xadp.substring(0,3), 10);
if (p4 > 4) { p3 += 0; }
idata[1] = String(p3);
ZLine = idata[0] + "." + idata[1];
return(ZLine);
}
%>

如果有人可以帮助我们非常感激

0 个答案:

没有答案