- type
- MoneyType = Currency; //这里可以是Double,但是浮点数存在误差,也可以是Currency,但是大小有限制
- function ChineseCapital2Money(Capital:WideString): MoneyType;
- var
- szNum:PWideChar;
- Sign: MoneyType;
- dblCurrent: MoneyType;
- I,iCount: Integer;
- begin
- Result := 0;
- iCount := Length(Capital);
- szNum := PWideChar(Capital);
- if szNum^ = #$8d1f(*'负'*) then begin
- Sign := -1;
- Inc(szNum);
- Dec(iCount);
- end else begin
- Sign := 1;
- end;
- while iCount > 0 do
- begin
- case szNum^ of
- #$96f6(*'零'*): begin
- dblCurrent := 0;
- end;
- #$58f9(*'壹'*): begin
- dblCurrent := 1;
- end;
- #$8d30(*'贰'*): begin
- dblCurrent := 2;
- end;
- #$53c1(*'叁'*): begin
- dblCurrent := 3;
- end;
- #$8086(*'肆'*): begin
- dblCurrent := 4;
- end;
- #$4f0d(*'伍'*): begin
- dblCurrent := 5;
- end;
- #$9646(*'陆'*): begin
- dblCurrent := 6;
- end;
- #$67d2(*'柒'*): begin
- dblCurrent := 7;
- end;
- #$634c(*'捌'*): begin
- dblCurrent := 8;
- end;
- #$7396(*'玖'*): begin
- dblCurrent := 9;
- end;
- //十百千
- #$62fe(*'拾'*): begin
- Result := Result + dblCurrent * 10.0;
- dblCurrent := 0;
- end;
- #$4f70(*'佰'*): begin
- Result := Result + dblCurrent * 100.0;
- dblCurrent := 0;
- end;
- #$4edf(*'仟'*): begin
- Result := Result + dblCurrent * 1000.0;
- dblCurrent := 0;
- end;
- //万亿
- #$4e07(*'万'*): begin
- Result := (Result + dblCurrent) * 10000.0;
- dblCurrent := 0;
- end;
- #$4ebf(*'亿'*): begin
- Result := (Result + dblCurrent) * 100000000.0;
- dblCurrent := 0;
- end;
- //元角分
- #$5143(*'元'*): begin
- Result := Result + dblCurrent;
- dblCurrent := 0;
- end;
- #$89d2(*'角'*): begin
- Result := Result + dblCurrent * 0.1;
- dblCurrent := 0;
- end;
- #$5206(*'分'*): begin
- Result := Result + dblCurrent * 0.01;
- dblCurrent := 0;
- break;
- end;
- //整
- #$6574(*'整'*): begin
- break;
- end;
- else
- Raise Exception.Create('输入源错误!');
- end;
- Inc(szNum);
- Dec(iCount);
- end;
- Result := Result * Sign;
- end;
人民币中文大写转金额
最新推荐文章于 2024-08-06 14:53:17 发布