Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > ASP.NET > 将数字转换成汉字的一段asp程序
【标  题】:将数字转换成汉字的一段asp程序
【关键字】:asp
【来  源】:http://blog.csdn.net/precipitant/archive/2005/12/19/556351.aspx

将数字转换成汉字的一段asp程序

Your Ad Here


'--------------------数字向汉字转换的函数集合  ------------------------
'作者:northsnow   
'日期:20051217
'调用方法:  a=convertNumToStr("1234.5678")
'功能: 将这样的串  1234.5678 转换成 一千二百三十四点五六七八


''将一串数字转成对应的汉字
 function convertNumToStr(pNum)
    dim oNum,rValue
    oNum=pNum:rValue=""
   
    '如果给定的不是合理的数字,则返回空串
    if not CheckPattern(oNum,z_PatNum) then
       ConvertNumToStr=rValue
       exit function
    end if  
   
    '将数字前面无用的0去掉
    set rLjc=new RegExp
    rLjc.Pattern="^0{2,}([^.])"
    oNum=rLjc.Replace(oNum,"$1")
    rLjc.Pattern="^0{2,}(\.)"
    oNum=rLjc.Replace(oNum,"0$1")
   
    '将小数点前后部分分开
    arrNum=split(oNum,".")
    frontNum=arrNum(0)
    backNum=""
    if ubound(arrNum)>0 then backNum=arrNum(1)
   
    '----  转换小数点前面的数----
    oLen=len(frontNum)
  
    if oLen=1 then   '只有一位
       rValue=convertNumToCC(frontNum)
    elseif oLen=2 then   '只有两位
       if(mid(frontNum,1,1))<>"1" then  rValue=convertNumToCC(mid(frontNum,1,1))
       rValue=rValue & getDigit(2)
       if(mid(frontNum,2,1))<>"0" then rValue=rValue & convertNumToCC(mid(frontNum,2,1))
    else   '大于两位的情况
       dim curPos,curNum,hasZero
       hasZero=false  '表明在此前有没有相连接的零
       for i=1 to oLen
          curPos=oLen-i + 1
          curNum=mid(frontNum,i,1)
          if cint(curNum)=0 then     '当前位数为零
              hasZero=true
              '当当前位为万位或者亿位,则进行处理
              if (curPos -1) mod 4=0 and curPos>4 then
     rValue=rValue & getDigit(curPos)
     end if
          else   '当前位数不是零
              if hasZero then
               rValue=rValue & "零"
      hasZero=false
     end if
     rValue=rValue & convertNumToCC(curNum) & getDigit(curPos)
          end if
       next 
    end if
   
    '转换小数点后面的
    if backNum<>"" then
       strBack=""
       for i=1 to len(backNum)
          strBack=strBack & convertNumToCC(mid(backNum,i,1))
       next
       rValue=rValue & "点" & strBack
    end if
    convertNumToStr=rValue
 end function
 
 
 ''将一个数字转成对应的汉字
 function convertNumToCC(pNum)
    select case pNum
      case 1:convertNumToCC="一"
      case 2:convertNumToCC="二"
      case 3:convertNumToCC="三"
      case 4:convertNumToCC="四"
      case 5:convertNumToCC="五"
      case 6:convertNumToCC="六"
      case 7:convertNumToCC="七"
      case 8:convertNumToCC="八"
      case 9:convertNumToCC="九"
      case 0:convertNumToCC="零"
    end select
 end function
 
 '根据位数返回对应的汉字
 function getDigit(oDigit)
    if (oDigit+2) mod 4=0 then
        getDigit="十"
    elseif (oDigit +1) mod 4=0 then
        getDigit="百"
    elseif oDigit mod 4=0 then
        getDigit="千"
    elseif (oDigit -1) mod 4=0 then
        if ((oDigit-1)/4) mod 2=0 then
            getDigit="亿"
        else
            getDigit="万"
        end if
    end if
 end function

搜索引擎设计实用教程-以百度为例(二):【上一篇】
初级黑客安全技术命令详解(一):【下一篇】
【相关文章】
  • [C++之AOP]Aspect C++生成远程调用代码可能性探讨
  • Java中基于Aspectwerkz的AOP
  • Asp.Net StartKits之Asp.Net Issue Tracker Starter Kit-数据库
  • [C++之AOP]实战Aspect C++之检查内存泄漏
  • [C++之AOP]实战Aspect C++之观察者模式
  • 用ASP编程实现网络内容快速查找
  • 简单的flash与asp.net通信(LoadVars类)
  • 使用ASP.NET 2.0 Profile存储用户信息[翻译] Level 200
  • 存档:ASP中的Scripting.FileSystemObject对象使用说明
  • asp.net下进行数据库安装与初始化化的例子
  • 【随机文章】
  • 用asp处理access数据库
  • “当页面跳转或者关闭窗口时弹出提示窗口!”JAVASCRIPT实例
  • 我听了并不惊奇
  • FREEBSD系统FAQ
  • Dreamweaver构建Blog全程实录(3)-数据库的设计和连接
  • PowerBuilder7、8、9程序无法升级到PowerBuilder10.x的原因及解决方法
  • 内存基础知识专题
  • OO设计模式简介
  • 引导型病毒的清除
  • java字符串转换成数字
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.