新疆软件开发

本站首页 软件开发 成功案例 公司新闻 公司简介 客服中心 软件技术 网站建设
  您现在的位置: 新疆二域软件开发公司 >> 开发语言 >> 文章正文

delphi英文数字转中文数字的办法

(*//
标题:中文数字表达
说明:普通方式和货币方式;和其它算法思路不一样;建议参考比较一下
设计:Zswang
日期:2002-01-25
支持:wjhu111@21cn.com
//*)

///////Begin Source
function NumberCn(mNumber: Real): WideString;
const
  cPointCn: WideString =  '点十百千万十百千亿十百千';
  cNumberCn: WideString =  '零一二三四五六七八九';
var
  I, L, P: Integer;
  S: string;
begin
  Result := '';
  if mNumber = 0 then begin
    Result := cNumberCn[1];
    Exit;
  end;
  S := FloatToStr(mNumber);
  if Pos('.', S) <= 0 then S := S + '.';
  P := Pos('.', S);
  L := Length(S);
  for I := 1 to L do
    if P > I then
      Result := Result + cNumberCn[StrToInt(S[I]) + 1] + cPointCn[P - I]
    else if P = I then begin
      Result := StringReplace(Result, '零十零', '零', [rfReplaceAll]);
      Result := StringReplace(Result, '零百零', '零', [rfReplaceAll]);
      Result := StringReplace(Result, '零千零', '零', [rfReplaceAll]);
      Result := StringReplace(Result, '零十', '零', [rfReplaceAll]);
      Result := StringReplace(Result, '零百', '零', [rfReplaceAll]);
      Result := StringReplace(Result, '零千', '零', [rfReplaceAll]);
      Result := StringReplace(Result, '零万', '万', [rfReplaceAll]);
      Result := StringReplace(Result, '零亿', '亿', [rfReplaceAll]);
      Result := StringReplace(Result, '亿万', '亿', [rfReplaceAll]);
      Result := StringReplace(Result, '零点', '点', [rfReplaceAll]);
    end else if P < I then
      Result := Result + cNumberCn[StrToInt(S[I]) + 1];
  if Result[Length(Result)] = cPointCn[1] then
    Result := Copy(Result, 1, Length(Result) - 1);
  if Result[1] = cPointCn[1] then Result := cNumberCn[1] + Result;
  if (Length(Result) > 1) and (Result[2] = cPointCn[2]) and
    (Result[1] = cNumberCn[2]) then
    Delete(Result, 1, 1);
end; { NumberCn }

function MoneyCn(mMoney: Real): WideString;
var
  P: Integer;
begin
  if mMoney = 0 then begin
    Result := '无';
    Exit;
  end;
  Result := NumberCn(Round(mMoney * 100) / 100);
  Result := StringReplace(Result, '一', '壹', [rfReplaceAll]);
  Result := StringReplace(Result, '二', '贰', [rfReplaceAll]);
  Result := StringReplace(Result, '三', '叁', [rfReplaceAll]);
  Result := StringReplace(Result, '四', '肆', [rfReplaceAll]);
  Result := StringReplace(Result, '五', '伍', [rfReplaceAll]);
  Result := StringReplace(Result, '六', '陆', [rfReplaceAll]);
  Result := StringReplace(Result, '七', '柒', [rfReplaceAll]);
  Result := StringReplace(Result, '八', '捌', [rfReplaceAll]);
  Result := StringReplace(Result, '九', '玖', [rfReplaceAll]);
  Result := StringReplace(Result, '九', '玖', [rfReplaceAll]);
  Result := StringReplace(Result, '十', '拾', [rfReplaceAll]);
  Result := StringReplace(Result, '百', '佰', [rfReplaceAll]);
  Result := StringReplace(Result, '千', '仟', [rfReplaceAll]);
  P := Pos('点', Result);
  if P > 0 then begin
    Insert('分', Result, P + 3);
    Insert('角', Result, P + 2);
    Result := StringReplace(Result, '点', '圆', [rfReplaceAll]);
    Result := StringReplace(Result, '角分', '角', [rfReplaceAll]);
    Result := StringReplace(Result, '零分', '', [rfReplaceAll]);
    Result := StringReplace(Result, '零角', '', [rfReplaceAll]);
    Result := StringReplace(Result, '分角', '', [rfReplaceAll]);
    if Copy(Result, 1, 2) = '零圆' then
      Result := StringReplace(Result, '零圆', '', [rfReplaceAll]);
  end else Result := Result + '圆整';
  Result := '人民币' + Result;
end; { MoneyCn }
///////End Source

///////Begin Demo
procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.Text := MoneyCn(StrToFloatDef(Edit3.Text, 0));
  Edit2.Text := NumberCn(StrToFloatDef(Edit3.Text, 0));
end;
///////End Demo

作者:未知 | 文章来源:未知 | 更新时间:2007-11-4 13:19:52

  • 上一篇文章:

  • 下一篇文章:

  • 相关文章:
    .net将视频文件格式转换成flv格式
    C#如何转换AVI文件为BMP位图文件
    GB/Unicode/GBK之间的转换
    软件技术
    · 开发语言
    · Java技术
    · .Net技术
    · 数据库开发
    最新文章  
    ·搜集整理的asp.net的验证方
    ·各种FOR循环结构的整理
    ·软件项目开发中应该考虑那
    ·搜集整理的javascript sel
    ·软件开发中项目经理有那些
    ·学习如何在Lambda表达式进
    ·C++基础知识:结构体数据的
    ·C#实现短信发送程序的例子
    ·sun最近修补了一部分java的
    ·rss定制的另外一种实现方式
    ·delphi实现利用arp欺骗来实
    ·基础学习:基于WF的流程框
    ·网络编程中怎样得知一次数
    ·如何逆序输出单链表?
    ·软件开发过程中的性能设计
    关于我们 | 软件开发 | 下载试用 | 客服中心 | 联系我们 | 友情链接 | 网站地图 | 新疆电子地图 | RSS订阅
    版权所有 © 2016 新疆二域软件开发网 www.k8w.net All Rights Reserved 新ICP备14003571号
    新疆软件开发总机:0991-4842803、4811639.
    客服QQ:596589785 ;地址:新疆乌鲁木齐北京中路华联大厦A-5C 邮编:830000