Форум: "Основная";
Текущий архив: 2003.03.17;
Скачать: [xml.tar.bz2];
ВнизПодскажите как перевести числовые значения в слова. Найти похожие ветки
← →
Rule (2003-03-05 01:52) [0]Помогите надо чтобы числа переводились в написной вариант (слвами). Подскажите гед взять компоненту или код, желательно чтобы на украинском языке. Или посоветуйте, какие трудности могут встретится на пути решения данного вопроса ???
← →
XsID (2003-03-05 02:05) [1]Вот есть одно решение.
function txt(s:integer):string;
function convert(M:integer):string;
const
c1to9:array [1..9] of string[7] = ("одна", "дві", "три", "чотири", "п`ять", "шість", "сім", "вісім", "дев`ять");
c11to19:array [1..9]of string[12] = ("одинадцять", "дванадцять", "тринадцять", "чотирнадцять", "п`ятнадцять",
"щістнадцять", "сімнадцять", "вісімнадцять", "дев`ятнадцять");
c10to90:array [1..9] of string[13]=("десять", "двадцять", "тридцять","сорок", "п`ятдесять", "шістдесят", "сімдесят", "вісімдесят", "дев`яносто");
c100to900:array [1..9] of string[10]=("сто", "двісті", "триста", "чотириста", "п`ятсот", "шістсот", "сімсот", "вісімсот", "дев`ятсот");
var
s:string;
i:integer;
begin
s:="";
i:=M div 100;
if i<>0 then s:= c100to900[i]+" ";
M:=M mod 100;
i:=M div 10;
if (M>10)and(M<20) then
s:=s+c11to19[M-10]+" "
else begin
if i<>0 then s:=s+c10to90[i]+" ";
M:=M mod 10;
if M<>0 then
s:=s+c1to9[M];
end;
Convert:=s;
end;
var
i,j:integer;
r:real;
t:string;
begin
t:="";
j:=trunc(s/1000000000);
r:=j;
r:=s-r*1000000000;
i:=trunc(r);
i:=i mod 1000000;
j:=i div 1000;
if j<>0 then begin
t:=t+convert(j)+" тисяч";
j:=j mod 100;
if (j>10)and(j<20) then t:=t+" "
else
case j mod 10 of
0: t:=t+" ";
1: t:=t+"а ";
2..4: t:=t+"і ";
5..9: t:=t+" ";
end
end;
i:= i mod 1000;
j:=i;
if j<>0 then t:=t+convert(j);
t:=t+" грн.";
txt:=t+" 00 коп.";
end;
← →
Rule (2003-03-05 02:21) [2]Огромаднейшее спсибище, есть у кого ещё предложения ???
← →
Мыш (2003-03-05 04:11) [3]А эта чего не работает, что ли?
Ну вот еще вариант:
unit MoneyStr;
//Перевод чисел в прописной эквивалент.
//(с)2001 Дмитрий Ларин aka [b]repairman[/b], Moscow, Russia
//repаirman@uzel.ru
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TSex=(sMale,sFemale);
TMultiplyer=record
Sex:TSex;
One:string;
Two:string;
Five:string;
end;
TCurrType=(ctDoll,ctRub,ctNeutral,ctNone);
TMoneyStr = class(TComponent)
private
FMoneyDig:real;
FMoneyStr:string;
FCurrType:TCurrType;
FTrailingNulls:boolean;
function Convert3Digits(Value:integer;Sex:TSex;Nulls:boolean):string;
function GetMultiplyerByLink(var Arr:TMultiplyer;Value:Integer):string;
function GetMultiplyerFrac(Value:integer):string;
function MakeFracPart(FracPart:integer):string;
function MakeIntPart(IntPart:int64):string;
function GetMultiplyerInt(Triada:integer):TMultiplyer;
procedure SetCurrencyType(CurrType:TCurrType);
procedure SetTrailingNulls(TNulls:boolean);
procedure Convert(InDig:real);
protected
public
published
property MoneyDig:real read FMoneyDig write Convert;
property MoneyStr:string read FMoneyStr write FMoneyStr;
property CurrencyType:TCurrType read FCurrType write SetCurrencyType;
property TrailingNulls:boolean read FTrailingNulls write SetTrailingNulls;
end;
procedure Register;
//-----------------------------------------------------------
implementation
const
//--------------------------------------------------------------
//Единицы мужского/женского рода
Ones:array [0..9,sMale..sFemale] of string=(("ноль","ноль"),
("один","одна"),
("два","две"),
("три","три"),
("четыре","четыре"),
("пять","пять"),
("шесть","шесть"),
("семь","семь"),
("восемь","восемь"),
("девять","девять"));
//-------------------------------------------------------------
//10..19
Tenth:array [0..9] of string=("десять",
"одинадцать",
"двенадцать",
"тринадцать",
"четырнадцать",
"пятнадцать",
"шестнадцать",
"семнадцать",
"восемнадцать",
"девятнадцать");
//-------------------------------------------------------------
//Десятки
Tens:array [2..9] of string=("двадцать",
"тридцать",
"сорок",
"пятьдесят",
"шестьдесят",
"семьдесят",
"восемьдесят",
"девяносто");
//----------------------------------------------------------
//Сотни
Handreds:array [1..9] of string=("сто",
"двести",
"триста",
"четыреста",
"пятьсот",
"шестьсот",
"семьсот",
"восемьсот",
"девятьсот");
//--------------------------------------------------------
//Множители род и в склонениях
Thausands:TMultiplyer= (Sex:sFemale;
One: "тысяча";
Two: "тысячи";
Five:"тысяч");
Millions:TMultiplyer= (Sex:sMale;
One: "миллион";
Two: "миллиона";
Five:"миллионов");
Milliards:TMultiplyer= (Sex:sMale;
One: "миллиард";
Two: "миллиарда";
Five:"миллиардов");
Trillions:TMultiplyer= (Sex:sMale;
One: "триллион";
Two: "триллиона";
Five:"триллионов");
//--------------------------------------------------------------
//Рубли - копейки (ctRub)
Rubles:TMultiplyer= (Sex:sMale;
One: "рубль";
Two: "рубля";
Five:"рублей");
Kopecs:TMultiplyer= (Sex:sFemale;
One: "копейка";
Two: "копейки";
Five:"копеек");
//-------------------------------------------------------------
nd.
← →
Мыш (2003-03-05 04:12) [4]продолжение
//Доллары - центы (ctDoll)
Dollars:TMultiplyer= (Sex:sMale;
One: "доллар";
Two: "доллара";
Five:"долларов");
Cents:TMultiplyer= (Sex:sMale;
One: "цент";
Two: "цента";
Five:"центов");
//------------------------------------------------------------
//Нейтральные числа (ctNeutral)
Neutrals:TMultiplyer= (Sex:sFemale;
One:"целая";
Two:"целые";
Five:"целых");
NeutralsI:TMultiplyer= (Sex:sFemale;
One:"сотая";
Two:"сотых";
Five:"сотых");
//------------------------------------------------------------
//Без рода
Nones:TMultiplyer= (Sex:sMale;
One:"";
Two:"";
Five:"");
//---------------------------------------------
procedure Register;
begin
RegisterComponents("[b]repairman[/b] Comps", [TMoneyStr]);
end;
//-----------------------------------------------------------
procedure TMoneyStr.SetTrailingNulls(TNulls:boolean);
begin
FTrailingNulls:=TNulls;
Convert(FMoneyDig);
end;
//-----------------------------------------------------------
procedure TMoneyStr.SetCurrencyType(CurrType:TCurrType);
begin
FCurrType:=CurrType;
Convert(FMoneyDig);
end;
//-----------------------------------------------------------
procedure TMoneyStr.Convert(InDig:real);
var IntPart:int64;
FracPart:integer;
begin
FMoneyStr:="";
FMoneyDig:=InDig;
IntPart:=Trunc(FMoneyDig);
FracPart:=Round(Frac(FMoneyDig)*100);
FMoneyStr:=MakeFracPart(FracPart);
FMoneyStr:=MakeIntPart(IntPart)+FMoneyStr;
FMoneyStr:=Trim(FMoneyStr);
end;
//-----------------------------------------------------------
function TMoneyStr.MakeIntPart(IntPart:int64):string;
var TempI1:int64;
TempI2:integer;
Triada:byte;
Mult:TMultiplyer;
TempS:string;
begin
Result:="";
Triada:=1;
TempI1:=IntPart;
repeat
Mult:=GetMultiplyerInt(Triada);
TempI2:=TempI1 mod 1000;
if (TempI2>0) or (Triada=1) then
begin
TempS:=Convert3Digits(TempI2,Mult.Sex,(TempI1=TempI2))+" ";
if (TempI2 mod 100) in [10..19] then TempS:=TempS+Mult.Five+" " else
case (TempI2 mod 10) of
1 : TempS:=TempS+Mult.One+" ";
2..4: TempS:=TempS+Mult.Two+" ";
else TempS:=TempS+Mult.Five+" ";
end;
Result:=TempS+Result;
end;
TempI1:=TempI1 div 1000;
inc(Triada);
until TempI1=0;
end;
//-----------------------------------------------------------
function TMoneyStr.MakeFracPart(FracPart:integer):string;
begin
Result:="";
if (FracPart=0) and (not FTrailingNulls) then Exit;
case FCurrType of
ctNone:Exit;
ctNeutral:Result:=Convert3Digits(FracPart,sFemale,True);
ctDoll:Result:=Convert3Digits(FracPart,sMale,True);
ctRub:Result:=Convert3Digits(FracPart,sFemale,True);
end;
Result:=Result+" "+GetMultiplyerFrac(FracPart);
end;
//-----------------------------------------------------------
function TMoneyStr.Convert3Digits(Value:integer;Sex:TSex;Nulls:boolean):string;
var Digits:array[1..3] of byte;
begin
Result:="";
if Value=0 then
begin
if Nulls then Result:=Ones[0,Sex];
Exit;
end;
Digits[1]:=(Value div 100) mod 10;
Digits[2]:=(Value div 10) mod 10;
Digits[3]:=Value mod 10;
if Digits[1] in [1..9] then Result:=Result+Handreds[Digits[1]]+" ";
if Digits[2]=1 then Result:=Result+Tenth[Digits[3]] else
begin
if Digits[2] in [2..9] then Result:=Result+Tens[Digits[2]]+" ";
if Digits[3] in [1..9] then Result:=Result+Ones[Digits[3],Sex];
end;
Result:=Trim(Result);
end;
//------------------------------------------------------------
function TMoneyStr.GetMultiplyerByLink(var Arr:TMultiplyer;Value:integer):string;
var LastDigit:byte;
begin
if (Value mod 100) in [10..19] then Result:=Arr.Five else
begin
LastDigit:=Value mod 10;
Result:="";
case LastDigit of
1 : Result:=Arr.One;
2..4 : Result:=Arr.Two;
else Result:=Arr.Five;
end;
end;
end;
//------------------------------------------------------------
function TMoneyStr.GetMultiplyerFrac(Value:Integer):string;
begin
Result:="";
case FCurrType of
ctNone :Exit;
ctNeutral :Result:=GetMultiplyerByLink(NeutralsI,Value);
ctDoll :Result:=GetMultiplyerByLink(Cents,Value);
ctRub :Result:=GetMultiplyerByLink(Kopecs,Value);
end;
end;
//------------------------------------------------------------
function TMoneyStr.GetMultiplyerInt(Triada:integer):TMultiplyer;
begin
case Triada of
1:
begin
case FCurrType of
ctRub :Result:=Rubles;
ctDoll :Result:=Dollars;
ctNeutral:Result:=Neutrals;
ctNone :Result:=Nones;
end;
end;
2:Result:=Thausands;
3:Result:=Millions;
4:Result:=Milliards;
5:Result:=Trillions;
end;
end;
//------------------------------------------------------------
e
Страницы: 1 вся ветка
Форум: "Основная";
Текущий архив: 2003.03.17;
Скачать: [xml.tar.bz2];
Память: 0.49 MB
Время: 0.008 c