我们昨天考了这样一道题:说是在文件框(text1) 每输一个数字的同时,在另一个文本框(text2)框里按财务读写习惯显示其金额。如45.56 读作 肆拾伍圆伍角陆分

解决方案 »

  1.   

    text1判断所输入的数字,后取对应的肆拾伍圆伍角陆分在ext2显示就行了。。
      

  2.   

    你说的是例子,text1中输入的是任意数值
      

  3.   

    网上到处都有
    function NumToChnStr(Value:Real;ClearZero:Boolean): String;
    const
      ChnUnit: array[0..13] of string = ('分', '角', '圆', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟');
      ChnNum : array[0..9] of string = ('零', '壹','贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
    var
      I: Integer;
      StrValue, StrNum: String;
      ValueLen: Integer;
    begin
      if Value <= 0 then
      begin
        Result := '输入参数应大于零。';
        Exit;
      end;
      StrValue := IntToStr(Round(Value * 100));
      ValueLen := Length(StrValue);
      Result := '';
      for I := 1 to ValueLen do
      begin
        StrNum := StrValue[I];
        Result := Result + ChnNum[StrToInt(StrNum)] + ChnUnit[ValueLen - I];
      end;
      if ClearZero 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]);
      end;
    end;
      

  4.   


    function NumToChnStr(Value:Real;ClearZero:Boolean): String;
    const
      ChnUnit: array[0..13] of string = ('分', '角', '圆', '拾', '佰', '仟', '万', '拾', '佰', '仟', '亿', '拾', '佰', '仟');
      ChnNum : array[0..9] of string = ('零', '壹','贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
    var
      I: Integer;
      StrValue, StrNum: String;
      ValueLen: Integer;
    begin
      if Value <= 0 then
      begin
        Result := '输入参数应大于零。';
        Exit;
      end;
      StrValue := IntToStr(Round(Value * 100));
      ValueLen := Length(StrValue);
      Result := '';
      for I := 1 to ValueLen do
      begin
        StrNum := StrValue[I];
        Result := Result + ChnNum[StrToInt(StrNum)] + ChnUnit[ValueLen - I];
      end;
      if ClearZero 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]);
      end;
    end;procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      if not (key in ['0'..'9','.']) then
      begin
         key:= #0;
      end;
    end;procedure TForm1.Edit1Change(Sender: TObject);
    begin
      edit2.Text:= NumToChnStr(StrToFloat(edit1.Text),true);
    end;