人民币中文大写转金额

 
  1. type
  2.   MoneyType = Currency; //这里可以是Double,但是浮点数存在误差,也可以是Currency,但是大小有限制
  3. function ChineseCapital2Money(Capital:WideString): MoneyType;
  4. var
  5.   szNum:PWideChar;
  6.   Sign: MoneyType;
  7.   dblCurrent: MoneyType;
  8.   I,iCount: Integer;
  9. begin
  10.   Result := 0;
  11.   iCount := Length(Capital);
  12.   szNum := PWideChar(Capital);
  13.   if szNum^ = #$8d1f(*'负'*) then begin
  14.     Sign := -1;
  15.     Inc(szNum);
  16.     Dec(iCount);
  17.   end else begin
  18.     Sign := 1;
  19.   end;
  20.   while iCount > 0 do
  21.     begin
  22.       case szNum^ of
  23.         #$96f6(*'零'*)begin
  24.           dblCurrent := 0;
  25.         end;
  26.         #$58f9(*'壹'*)begin
  27.           dblCurrent := 1;
  28.         end;
  29.         #$8d30(*'贰'*)begin
  30.           dblCurrent := 2;
  31.         end;
  32.         #$53c1(*'叁'*)begin
  33.           dblCurrent := 3;
  34.         end;
  35.         #$8086(*'肆'*)begin
  36.           dblCurrent := 4;
  37.         end;
  38.         #$4f0d(*'伍'*)begin
  39.           dblCurrent := 5;
  40.         end;
  41.         #$9646(*'陆'*)begin
  42.           dblCurrent := 6;
  43.         end;
  44.         #$67d2(*'柒'*)begin
  45.           dblCurrent := 7;
  46.         end;
  47.         #$634c(*'捌'*)begin
  48.           dblCurrent := 8;
  49.         end;
  50.         #$7396(*'玖'*)begin
  51.           dblCurrent := 9;
  52.         end;
  53.         //十百千
  54.         #$62fe(*'拾'*)begin
  55.           Result := Result + dblCurrent * 10.0;
  56.           dblCurrent := 0;
  57.         end;
  58.         #$4f70(*'佰'*)begin
  59.           Result := Result + dblCurrent * 100.0;
  60.           dblCurrent := 0;
  61.         end;
  62.         #$4edf(*'仟'*)begin
  63.           Result := Result + dblCurrent * 1000.0;
  64.           dblCurrent := 0;
  65.         end;
  66.         //万亿
  67.         #$4e07(*'万'*)begin
  68.           Result := (Result + dblCurrent) * 10000.0;
  69.           dblCurrent := 0;
  70.         end;
  71.         #$4ebf(*'亿'*)begin
  72.           Result := (Result + dblCurrent) * 100000000.0;
  73.           dblCurrent := 0;
  74.         end;
  75.         //元角分
  76.         #$5143(*'元'*)begin
  77.           Result := Result + dblCurrent;
  78.           dblCurrent := 0;
  79.         end;
  80.         #$89d2(*'角'*)begin
  81.           Result := Result + dblCurrent * 0.1;
  82.           dblCurrent := 0;
  83.         end;
  84.         #$5206(*'分'*)begin
  85.           Result := Result + dblCurrent * 0.01;
  86.           dblCurrent := 0;
  87.           break;
  88.         end;
  89.         //整
  90.         #$6574(*'整'*)begin
  91.           break;
  92.         end;
  93.         else
  94.           Raise Exception.Create('输入源错误!');
  95.       end;
  96.       Inc(szNum);
  97.       Dec(iCount);
  98.     end;
  99.   Result := Result * Sign;
  100. end;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值