发现google计算器,感觉我的数字大小写转换程序有点意思!


  <SCRIPT LANGUAGE="JScript">
   function CheckValueA()
   {
     var isOk = true;
     if (document.formA.lowA.value.length<1) isOk = false ;
     if (document.formA.highA.value.length<1) isOk = false ;
     if (document.formA.baseA.value.length<1) isOk = false ;
     if (document.formA.perA.value.length<1) isOk = false ;  
     if (!isOk) alert("有效字符:零0 一1壹 二2贰两 三3叁 四4肆 五5伍 六6陆 七7柒 八8捌 九9玖 十拾 分角毛元圆块百佰千仟万萬亿,.,.");  
     return isOk;
    }
   function CheckValueD()
   {
     var isOk = true;
     if (document.formD.lowD.value.length<1) isOk = false ;
     if (document.formD.highD.value.length<1) isOk = false ;
     if (document.formD.baseD.value.length<1) isOk = false ;
     if (document.formD.perD.value.length<1) isOk = false ;  
     if (!isOk) alert("有效字符:零0 一1壹 二2贰两 三3叁 四4肆 五5伍 六6陆 七7柒 八8捌 九9玖 十拾 分角毛元圆块百佰千仟万萬亿,.,.");  
     return isOk;
    }
  </SCRIPT>
 <SCRIPT LANGUAGE="JScript">
   function MoneyCheckValue()
   {
     var qisOk = true;
  var validChar=["零","一","二","三","四","五","六","七","八","九","十","0","1","2","3","4","5","6","7","8","壹","贰","叁","肆","伍","陆","柒","捌","玖","拾","分","角","毛","元","圆","百","佰","千","仟","万","萬","亿",",",".",",","."];
  var validStr="零0 一1壹 二2贰两 三3叁 四4肆 五5伍 六6陆 七7柒 八8捌 九9玖 十拾 分角毛元圆块百佰千仟万萬亿,.,.";
  var tempStr=num.value;
     if (num.value.length<1 || num.value.length>27)
  {  qisOk = false ;}
  else
  {
   for(var i=0;i<tempStr.length;i++)
   {
     if (validStr.indexOf(tempStr.substr(i,1)) == -1)
  {
   qisOk = false;
   alert("非法字符:"+tempStr.substr(i,1));
   break;
  }
    }
  }
    if (!qisOk) alert("有效字符:零0 一1壹 二2贰两 三3叁 四4肆 五5伍 六6陆 七7柒 八8捌 九9玖 十拾 分角毛元圆块百佰千仟万萬亿,.,.");  
     return qisOk;
    }
  </SCRIPT>
  <script  language="vbscript">
 
  function dealErr(eNo)
    Response.Redirect("converErr.asp?errno="&eNo)
  end function 
  dim errNo   
  errNo = 0 
  </script>
 
  <script language="VBScript">
      validStrDel=",,"
      validStrTo1="一壹"
      validStrTo2="二贰两"
   validStrTo3="三叁"
   validStrTo4="四肆"
   validStrTo5="五伍"
   validStrTo6="六陆"
   validStrTo7="七柒"
   validStrTo8="八捌"
   validStrTo9="九玖"
   validStrto0="零"
   validStrHold="0123456789十拾分角毛元圆块百佰千仟万萬亿.."
  function pretreatNum(numStr)
    dim tmpStr
 tmpStr=""
    for i=1 to len(numStr)
   theChar = mid(numStr,i,1)
   if inStr(validStrDel,theChar) then tmpStr=tmpStr
   if inStr(validStrTo1,theChar) then tmpStr=tmpStr & "1"
   if inStr(validStrTo2,theChar) then tmpStr=tmpStr & "2"
   if inStr(validStrTo3,theChar) then tmpStr=tmpStr & "3"
   if inStr(validStrTo4,theChar) then tmpStr=tmpStr & "4"
   if inStr(validStrTo5,theChar) then tmpStr=tmpStr & "5"
   if inStr(validStrTo6,theChar) then tmpStr=tmpStr & "6"
   if inStr(validStrTo7,theChar) then tmpStr=tmpStr & "7"
   if inStr(validStrTo8,theChar) then tmpStr=tmpStr & "8"
   if inStr(validStrTo9,theChar) then tmpStr=tmpStr & "9"
   if inStr(validStrTo0,theChar) then tmpStr=tmpStr & "0"  
   if inStr(validStrHold,theChar) then tmpStr=tmpStr & theChar
 next
    pretreatNum = tmpStr
  end function
 
  valSymbol0="0123456789"
  valSymbol1="分"
  valSymbol2="角毛"
  valSymbol3="元圆块" 
  valSymbol4="十拾"
  valSymbol5="百佰"
  valSymbol6="千仟"
  valSymbol7="万萬"
  valSymbol8="亿"
  valSymbol9=".." 

  function  parseNum(numStr)
    dim tmpStr
    dim tmpArr(28)
 dim wTimes
 dim yTimes
 dim isW 
 dim isY
 dim isTen
 dim isStar
 dim tPos
 dim cPos 
 dim tOff
 tOff = 0
 isStar = 1
 wTimes = 0
 yTimes = 0
 cPos = 2
    for i= 0 to 27
   tmpArr(i)="0"
 next

 for i= len(numStr) to 1 step -1
   theChar = mid(numStr,i,1)
   //0123456789
   if inStr(valSymbol0,theChar) then
    if cPos > 37 then
         dealErr(3)
    end if 
        if cPos =2 then
   isStar = 1
  else
    isStar = 0
  end if 
     if isTen = 1 then
    cPos = cPos -1
       tmpArr(cPos)=theChar
    isTen = 0
  else
    tmpArr(cPos)=theChar
  end if 
    cPos = cPos+1
    tOff = tOff+1  
   end if
   //分
   if inStr(valSymbol1,theChar) then
        isStar = 0  
     if cPos=2 then
       cPos = 0
  else
    dealErr(1)
        end if
  tOff = 0
   end if
   //角
   if inStr(valSymbol2,theChar) then
     isStar = 0
     if tOff<=1 then
    tmpArr(0)=CStr(CInt(tmpArr(0))+CInt(tmpArr(2)))
    tmpArr(2)="0"     
       cPos = 1
        else
    dealErr(1)
  end if
  tOff = 0  
   end if
   //元
   if inStr(valSymbol3,theChar) then
     if tOff<=1 then
    tmpArr(1)=CStr(CInt(tmpArr(1))+CInt(tmpArr(2)))
    tmpArr(2)="0" 
       cPos = 2
    //step0 = 2
  elseif tOff=2 then
    cPos = 2 
  else
    dealErr(1)
  end if   
  tOff = 0
   end if
   //十
   if inStr(valSymbol4,theChar) then
     isStar = 0
     tPos = 1
     cPos = tPos + wTimes*4+yTimes*8+2
     tmpArr(cPos)="1"
  cPos = cPos+1  
  isTen  = 1
  tOff = 0
   end if
   //百
   if inStr(valSymbol5,theChar) then
     tPos = 2
     cPos = tPos+ wTimes*4+yTimes*8+2    
  if isStar=1 then
    tmpArr(cPos-1)=tmpArr(2)
    tmpArr(2)="0"  
  end if
  isStar = 0
  tOff = 0
   end if
   //千
   if inStr(valSymbol6,theChar) then    
     tPos = 3
     cPos = tPos+ wTimes*4+yTimes*8+2
  if isStar=1 then  
    tmpArr(cPos-1)=tmpArr(2)
    tmpArr(2)="0"  
  end if   
  isStar = 0
  tOff = 0
   end if
   //万
   if inStr(valSymbol7,theChar) then     
      tPos = 0
   isW = 1
   wTimes = wTimes +1  
     cPos = tPos+ wTimes*4+yTimes*8+2
  if isStar=1 then
    tmpArr(cPos-1)=tmpArr(2)
    tmpArr(2)="0"  
  end if     
  isStar = 0 
  tOff = 0
   end if
   //亿
   if inStr(valSymbol8,theChar) then
      isStar = 0
      tPos = 0
   if isW=1 then
     isW=0
     wTimes = wTimes -1
   end if  
   yTimes = yTimes +1
   cPos = tPos+ wTimes*4+yTimes*8+2 
   tOff = 0
   end if 
   //.
   if inStr(valSymbol9,theChar) then
      if wTimes=0 and yTimes=0 then isStar = 1
   for j=0 to tOff
     cPos = j+ tPos+ wTimes*4+yTimes*8+2 
     if cPos-tOff>=0 then
       tmpArr(cPos-tOff)=CStr(CInt(tmpArr(cPos-tOff))+CInt(tmpArr(cPos)))
       tmpArr(cPos)="0" 
     else
       dealErr(2)
     end if 
   next 
   tOff = 0
   cPos = tPos+ wTimes*4+yTimes*8+2 
   end if               
 next
 for i=  27 to 0 step -1
  if tmpArr(i) <> "0" then
    iStar = i
    exit for
  end if
 next
 if iStar<2 then
   dealErr(4)
 end if
 for i=0 to iStar
   if i=1 then
     tmpStr ="." & tmpArr(i) & tmpStr
   else
     tmpStr = tmpArr(i) & tmpStr
   end if
 next 
 parseNum = tmpStr
  end function
 
  function toDbl(numStr)
   dim tmpStr
   tmpStr = CDbl(numStr)
   toDbl = tmpStr
  end function
 
  function toPrn0(numStr)
   dim tmpStr
   dim M3
   tmpStr=""
   M3 = 0
   for i = len(numStr) to 1 step -1
      if ((M3-2) mod 3)=0 and M3-2<>0 and i<>1 then
     tmpStr = ","&mid(numStr,i,1) & tmpStr 
   else
     tmpStr = mid(numStr,i,1) & tmpStr
   end if
   M3 = M3+1
   next
   toPrn0 = tmpStr
  end function 
 
  function toPrn1(numStr)
   dim tmpStr
   dim perStr
   dim M8
   M8=0
   dim valP0
   dim valP1
   perStr = ""
   valP = "拾佰仟万拾佰仟亿"
   for i = len(numStr) to 1 step -1
   //小写转打写
      tmpChar=mid(numStr,i,1)
      select case tmpChar
    case "0"
      perStr="零" & perStr
    case "1"
      perStr="壹" & perStr
    case "2"
      perStr="贰" & perStr
    case "3"
      perStr="叁" & perStr
    case "4"
      perStr="肆" & perStr
    case "5"
      perStr="伍" & perStr
    case "6"
      perStr="陆" & perStr
    case "7"
      perStr="柒" & perStr
    case "8"
      perStr="捌" & perStr
    case "9"
      perStr="玖" & perStr
    case "."
      perStr="圆" & perStr
   end select
   next
   for i = len(perStr) to 1 step -1
      M8 = M8 + 1
   if M8=1 then
    tmpStr =mid(perStr,i,1) & "分" & tmpStr
   elseif M8=2 then
    tmpStr =mid(perStr,i,1) & "角" & tmpStr
   elseif M8=3 then
    tmpStr =mid(perStr,i,1) & tmpStr
   elseif M8=4 then
    tmpStr =mid(perStr,i,1) & tmpStr
   else
    t=((M8-4) mod 8)
    if t=0 then
      t=8
    end if 
    tmpStr =mid(perStr,i,1) & mid(valP,t,1) & tmpStr  
   end if 
   next
   toPrn1 = tmpStr
  end function 
 
  function calculate(low,numStr,base,per)
   dim tmpStr
   tmpStr = (CDbl(numStr)-CDbl(low))*CDbl(per)+CDbl(base)
   tmpStr = FormatNumber(tmpStr,2)
   calculate=tmpStr   
  end function
  </script>
  <script language="vbscript">
  function show
    MoneyCheckValue()'遗憾
    document.write(toPrn0(toDbl(parseNum(pretreatNum(num.value)))))
  end function
  </script> 
  <input name="num" type="text" value="447"><input name="submit" type="button" onClick="vbscript:show">
 



你可能感兴趣的:(Google,J#,VBScript,asp)