Currency to spanish/english words

FAlvaradoFAlvarado US/Mexico
edited 9:16PM in FastReport VCL
HI All!
I was googling for a function to convert a currency value to Spanish words in FR VCL 6 and found three native functions for FastReport.Net to do this in English, GB English and even in Russian!
Why fast report for VCL doesn???t have these functions?
I already have a function to convert currency to Spanish words that works on Delphi 10.2 but not in Fast-Report VCL 5 nor 6.
Will FR will have feature like this in the near future?
Best Regards
Francisco Alvarado

Comments

  • edited 9:16PM
    I use the following code for a report which creates (in English) and word string for currency for FR VCL 6
    var
      Temp         : real;
      DigitA,DigitB: integer;
      Ams          : string;
      Ac           : string;
      NumStr       : TStringList;
    
       function TenUnittoWord(TeUn : integer) : string;
              { convert tens and units to words }
    
       begin
         if TeUn < 21 then Result := NumStr[TeUn]
           else Result := NumStr[TeUn div 10 + 18] + NumStr[TeUn mod 10];
       end;
    
    function NumberToWord(A:real) : string;
    begin
       { convert 1,000,000 decade }
       if (A>20000000.0) or (A <= 0.0) then
         begin
            Result := '';
            Exit;
         end;
       Ams := '*';
       DigitA := Trunc(A/1e6);
       if DigitA > 0 then Ams := Ams + NumStr[DigitA] + 'million ';
       Temp := A - DigitA * 1e6;
       {convert 100,000, 10,000 and 1,000 decades }
       DigitA := Trunc(Temp/1e5);                 {100,000}
       if DigitA > 0 then Ams := Ams + NumStr[DigitA] + 'hundred ';
       temp := temp - digita * 1e5;
       DigitB := Trunc(Temp/1000);
       Ams := Ams + TenUnitToWord(DigitB);
       if((digita>0) or (digitb>0)) then Ams := Ams + 'thousand ';
       temp := temp - digitb * 1000.0;
       digitA := Trunc(Temp/100);
       if DigitA > 0 then Ams := Ams + NumStr[DigitA] + 'hundred ';
       DigitB := Trunc(Temp - DigitA*100.0);
       Ams := Ams + TenUnitToWord(DigitB);
       if Int(A) > 0.0 then Ams := Ams + 'and ' else Ams := Ams + 'zero ';
       DigitA := Round((Frac(A)*100));
       if DigitA > 0 then
         begin
            {Str(DigitA:2,Ac);} AC := IntToStr(DigitA);
            if Length(AC)=1 then AC := ' '+AC ;
            if Ac[1] = ' ' then Ac[1] := '0';
            Ams := Ams + Ac + '/100'
         end
       else Ams := Ams + 'no/100';
       Ams[2]:=UpperCase(Ams[2]);
       Result := Ams + '*';
    end;
    
    
    
    procedure RptOnStartReport(Sender: TfrxComponent);
    begin
      NumStr := TStringList.Create;
      NumStr.Add('');
      NumStr.Add('one ');
      NumStr.Add('two ');
      NumStr.Add('three ');
      NumStr.Add('four ');
      NumStr.Add('five ');
      NumStr.Add('six ');
      NumStr.Add('seven ');
      NumStr.Add('eight ');
      NumStr.Add('nine ');
      NumStr.Add('ten ');
      NumStr.Add('eleven ');
      NumStr.Add('twelve ');
      NumStr.Add('thirteen ');
      NumStr.Add('fourteen ');
      NumStr.Add('fifteen ');
      NumStr.Add('sixteen ');
      NumStr.Add('seventeen ');
      NumStr.Add('eighteen ');
      NumStr.Add('nineteen ');
      NumStr.Add('twenty ');
      NumStr.Add('thirty ');
      NumStr.Add('forty ');
      NumStr.Add('fifty ');
      NumStr.Add('sixty ');
      NumStr.Add('seventy ');
      NumStr.Add('eighty ');
      NumStr.Add('ninety ');
    
    end;
    
    procedure RptOnStopReport(Sender: TfrxComponent);
    begin
      NumStr.Free;
    end;
    
    
    procedure txtAmountInWordsOnBeforePrint(Sender: TfrxComponent);
    begin
        txtAmountInWords.text := NumberToWord(<fdqTx."AMOUNT">);
      txtAmountInWords.Font.Size := 12;
      while txtAmountInWords.CalcWidth > txtAmountInWords.width do
        txtAmountInWords.font.size := txtAmountInWords.font.size-1;
    end;
    
    
    
    begin
    
    end.
    

    The currency field is in my query fdqTX as <fdqTX."AMOUNT">. You may need to adjust the routine for Spanish (besides the NumStr list)
  • FAlvaradoFAlvarado US/Mexico
    edited 9:16PM
    Thank you for your response, but the spanish version is somewhat more complicated...
    Several years I lost my collection of classes (I now I store backups in different places) and instead of reprogramming this class I'm using this one (http://www.trucomania.org/trucomania/ftesp.html) It's programmed by Vicente L??pez back in 2000!
    I had to make several adaptations to make it work in FR5 and FR6 but now it's working...
    I just wished FR had a native function, like Crystal Reports 8.5 did in English and in Spanish and FR for Net has for english and russian..
    Best Regards
    Francisco Alvarado
    brodzins wrote on Jun 24 2019, 11:08 AM:
    I use the following code for a report which creates (in English) and word string for currency for FR VCL 6

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.