Number to Letter

Fer CastroFer Castro Ciudad de M?©xico
edited 5:10AM in FastReport 4.0
Hello

I have a report and I need to print the number as well as the number into letter, ie:


$ 250.00 (TWO HUNDRED AND FIFTY DOLLARS 00/100 USCy)

Actually I have a function which converts numbers into letter, but I have no idea about how insert the function into the report,

Thanks and best regards


- Delphi XE
- Fast Report 4.13.1
- Devart UNIDAC

Comments

  • gordkgordk St.Catherines On. Canada.
    edited 5:10AM
    read the developers manual chapter on custom funtions.
  • Fer CastroFer Castro Ciudad de M?©xico
    edited 5:10AM
    gordk wrote: »
    read the developers manual chapter on custom funtions.

    Gordk,

    I really appreciate your help and your answer, but to tell you the truth I was expecting something like a sample. You can be sure I have read the manual 4 or 5 times in order to acomplish the task.

    But guess what, if I request help in the forum i'ts because my knowledge has limits. But again, I really appreciate your advice [img]style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Regards!![/img]
  • edited 5:10AM
    Hi.

    Instead of making a Delphi-side user function, you can simply put your function in the code of the report, before 'begin'.

    The function then can be used inside the report both in code and in MemoView's. In a MemoView you can put something like '[NumberToLetter(<MyQry."MyIntegerField">)]'.

    The main advantage of making a Delphi-side user function is that the function then can be used in all your reports.

    There is also another way to share code between reports: You can put your shared code in an external .pas-file, and connect this to your report by adding the filename to the uses clause in the beginning of your report's code. I think the .pas file by default (or always??) should be located where you have your .exe's.

    Here is an example of both internal function and attached .pas file.
    #language PascalScript
    
    uses 
      'MySharedCodeFile.pas';
    
    function NumberToLetter(Number: Integer): String;
    begin
      // Do your stuff here...
      Result := ...
    end;
    
    begin
    end.
    

    Petter
  • edited 5:10AM
    Use this code inside report'designer on Code's section:

    use: [FloatToEng('your_number_field')]



    //
    English ----
    function getNumEng(const Value:longint):string;
    begin
    case Value of
    0:result:='ZERO';
    1:result:='ONE';
    2:result:='TWO';
    3:result:='THREE';
    4:result:='FOUR';
    5:result:='FIVE';
    6:result:='SIX';
    7:result:='SEVEN';
    8:result:='EIGHT';
    9:result:='NINE';
    10:result:='TEN';
    11:result:='ELEVEN';
    12:result:='TWELVE';
    13:result:='THIRTEEN';
    14:result:='FOURTEEN';
    15:result:='FIFTEEN';
    16:result:='SIXTEEN';
    17:result:='SEVENTEEN';
    18:result:='EIGHTEEN';
    19:result:='NINETEEN';
    20:result:='TWENTY';
    30:result:='THIRTY';
    40:result:='FORTY';
    50:result:='FIFTY';
    60:result:='SIXTY';
    70:result:='SEVENTY';
    80:result:='EIGHTY';
    90:result:='NINETY';
    100:result:='HUNDRED';
    1000:result:='THOUSAND';
    1000000:result:='MILLION';
    end;
    end;

    function GetEng(const Value:longint):string;
    var Digit:integer;
    begin
    result:='';
    if Value=0 then exit;
    Digit:= Value div 1000000;
    if (Digit>0) then begin
    result:=GetEng(Digit)+' ' + GetNumEng(1000000);
    if (Value Mod 1000000) > 0 then
    result:=result+' '+GetEng(Value Mod 1000000);
    end
    else begin
    Digit:=Value Div 1000;
    if Digit>0 then begin
    result:=GetEng(Digit)+ ' ' + GetNumEng(1000);
    if (Value mod 1000)>0 then begin
    result:=result+' '+GetEng(Value Mod 1000);
    end;
    end
    else begin
    Digit:=Value Div 100;
    if Digit>0 then begin
    result:=GetEng(Digit) + ' ' + GetNumEng(100);
    if (Value mod 100)>0 then
    result:=result+GetEng(Value Mod 100);
    end
    else begin
    if Value > 20 then begin
    Digit:=Value Div 10;
    result:=GetNumEng(Digit*10);
    if (Value Mod (Digit*10))>0 then
    result:=result+GetNumEng(Value Mod (Digit*10));
    end
    else
    result:=getNumEng(Value);
    end;
    end;
    end;
    end;

    function FloatToEng(const value:extended) : String;
    var x:string;
    Svalue,First,Second:string;
    V,M:longint;
    begin
    result:='';
    if Value=0 then exit;
    SValue:=trim(floattostr(value));
    if pos('.',Svalue)>0 then begin
    First:=copy(SValue,1,pos('.',Svalue)-1);
    if First='' then First:='0';
    Second:=copy(SValue,pos('.',Svalue)+1,length(Svalue));
    end
    else begin
    First:=SValue;
    Second:='';
    end;
    result:='';
    V:=strtoint(First);
    if Value=0 then x:=GetNumEng(V) else
    if V>100 then begin
    M:=(V Mod 100);
    x:=GetEng(V-M);
    if M>0 then x:=x+' AND '+GetEng(M);
    end
    else x:=GetEng(V);
    result := x ;
    end;

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.