View Full Version : تبدیل عدد به حرف تا 999 میلیارد
  
nasr
یک شنبه 08 خرداد 1384, 10:59 صبح
سلام
اول بگم که خیلی Search کردم ولی چیزی پیدا نکردم
یه تابعی می خوام که اعداد را تا 999 میلیارد به حرف تبدیل کنه 
ممنون
دنیای دلفی
یک شنبه 08 خرداد 1384, 15:12 عصر
unit Curr2Str;
interface
function Add2Harf(i:int64):string;
implementation
function Add2Harf(i:int64):string;
const v=' و ';
var
    ok:boolean;
  {___________________________________}
  function yekan(y:byte):string;
  begin
    case y of
        0:result:='';
        1:result:='یک';
        2:result:='دو';
        3:result:='سه';
        4:result:='چهار';
        5:result:='پنج';
        6:result:='شش';
        7:result:='هفت';
        8:result:='هشت';
        9:result:='نه';
    enD;
    if result=''then ok:=false else ok:=true;
  end;
  {___________________________________}
  function dahgan(y:byte):string;
  begin
    case y of
        0:result:='';
        1:result:='ده';
        2:result:='بیست';
        3:result:='سی';
        4:result:='چهل';
        5:result:='پنجاه';
        6:result:='شصت';
        7:result:='هفتاد';
        8:result:='هشتاد';
        9:result:='نود';
    enD;
    if result=''then ok:=false else ok:=true;
  end;
  {___________________________________}
  function sadgan(y:byte):string;
  begin
    case y of
        0:result:='';
        1:result:='یکصد';
        2:result:='دویست';
        3:result:='سیصد';
        4:result:='چهارصد';
        5:result:='پانصد';
        6:result:='ششصد';
        7:result:='هفتصد';
        8:result:='هشتصد';
        9:result:='نهصد';
    enD;
    if result=''then ok:=false else ok:=true;
  end;
  {___________________________________}
  function dah(y:byte):string;
  begin
    case y of
        0:result:='';
        10:result:='ده';
        11:result:='یازده';
        12:result:='دوازده';
        13:result:='سیزده';
        14:result:='چهارده';
        15:result:='پانزده';
        16:result:='شانزده';
        17:result:='هفده';
        18:result:='هجده';
        19:result:='نوزده';
    enD;
    if result=''then ok:=false else ok:=true;
  end;
  {___________________________________}
  function seragham(si:smallint):string;
  begin
    result:='';
    result:=sadgan(si div 100);
    if ok then result:=result+v;
    if((si mod 100)div 10)<>1 then begin
        result:=result+dahgan((si mod 100)div 10);
        if ok then result:=result+v;
        result:=result+yekan(si mod 10);
        if not ok then result:=copy(result,1,length(result)-3);
    End
    else begin
        result:=result+dah(si mod 100);
    end;
    if result='' then ok:=false else ok:=true;
  end;
  {___________________________________}
const
    tr=' تریلیون';
    mr=' میلیارد';
    ml=' میلیون';
    hz=' هزار';
begin
    ok:=false;
    result:=seragham(i div 1000000000000);
    if ok then result:=result+tr+v;
    result:=result+seragham((i mod 1000000000000)div 1000000000);
    if ok then result:=result+mr+v;
    result:=result+seragham((i mod 1000000000)div 1000000);
    if ok then result:=result+ml+v;
    result:=result+seragham((i mod 1000000)div 1000);
    if ok then result:=result+hz+v;
    result:=result+seragham(i mod 1000);
    if not ok then result:=copy(result,1,length(result)-3);
    if i=0 then result:='صفر';
end;
end.
amir_22
پنج شنبه 23 شهریور 1385, 09:36 صبح
ممنون 
من هم همین مشکل را داشتم بر طرف شد
 
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.