Convert A Number into Words

Hello,

How can i convert a number into words. In invoices it is also required to write total in words.
How can i accomplish this in fr.

Comments

  • StarkStark Syria
    edited August 2010
    Hi

    I think you must convert the numbers to words in your application and pass it to report


    Hope this code help
    MessageBox.Show( FastReport.Functions.StdFunctions.ToWords(1500.5, "", ""));
    
  • edited 6:46AM
    Stark wrote: »
    Hi

    I think you must convert the numbers to words in your application and pass it to report


    Hope this code help
    MessageBox.Show( FastReport.Functions.StdFunctions.ToWords(1500.5, "", ""));
    


    Use this code on fast report'code section

    //
    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.