Белик Виталий :)
Старожил
Регистрация: 23.07.2007
Сообщений: 57,097
|
Код:
Function TellMoney(d:Double):String;
const
v:array[1..3,1..9] of String=(
('один', 'два', 'три', 'четыре', 'пять', 'шесть', 'семь', 'восемь', 'девять')
,('десять', 'двадцать', 'тридцать', 'сорок', 'пятьдесят', 'шестьдесят', 'семьдесят', 'восемьдесят', 'девяносто')
,('сто', 'двести', 'триста', 'четыреста', 'пятьсот', 'шестьсот', 'семьсот', 'восемьсот', 'девятьсот')
);
tsv:array[1..9] of String = ('тысяча', 'тысячи', 'тысячи', 'тысячи', 'тысяч', 'тысяч', 'тысяч', 'тысяч', 'тысяч');
var s,intt:String;pt,it,imln,imlrd,k,i,m:integer;
begin
FormatSettings.DecimalSeparator:='.';
s:=trim(Format('%10.2f',[d]));
pt:=pos('.',s);
k:=StrToIntDef(copy(s,1,pt-1),0);
Result:='';
if (k>10) and (k<20) then begin
if(k<>4) then Result:=v[1][k mod 10]+'надцать' else Result:='четырнадцать';
end else begin
it:=1; i:=1; imln:=1; imlrd:=1;
while( k > 0) do begin
m:= k mod 10;
if m<>0 then begin
if imlrd=10 then begin
i:=1;
case m of
1:intt:='миллиард';
2..4:intt:='миллиарда';
5..9:intt:='миллиардов';
end;
Result:=v[i][m] +' '+ intt + ' ' + Result;
end else
if imln=7 then begin
i:=1;
case m of
1:intt:='миллион';
2,3:intt:='миллиона';
4..9:intt:='миллионов';
end;
Result:=v[i][m] +' '+ intt + ' ' + Result;
end else
if it=4 then begin
i:=1;
if m<>1 then begin
Result:=v[i][m] +' '+ tsv[m] + ' ' + Result;
end else begin
Result:='одна '+ tsv[m] + ' ' + Result;
end;
end else begin
Result := v[i][m] + ' ' + Result;
end;
end;
k:=k div 10;
inc(i); inc(it); inc(imln); inc(imlrd);
end
end;
if Result<>'' then Result:=AnsiUpperCase(Result[1])+Copy(Result,2,Length(Result));
Result:=Result+' грн.';
if pt<>0 then
Result:=Result+' '+copy(s,pt+1,Length(s))+' коп.';
end;
Код:
function MoneyTell(n){
var v=[
['один', 'два', 'три', 'четыре', 'пять', 'шесть', 'семь', 'восемь', 'девять']
,['десять', 'двадцать', 'тридцать', 'сорок', 'пятьдесят', 'шестьдесят', 'семьдесят', 'восемьдесят', 'девяносто']
,['сто', 'двести', 'триста', 'четыреста', 'пятьсот', 'шестьсот', 'семьсот', 'восемьсот', 'девятьсот']
]
if(typeof(n) == 'number') n=''+n;
var tsv = ['тысяча', 'тысячи', 'тысячи', 'тысячи', 'тысяч', 'тысяч', 'тысяч', 'тысяч', 'тысяч'];
var a=n.split('.');
var res='';
var k=parseInt(a[0])
var i=0,m=0;
if (k > 10 && k < 20) {
if(k!=4) res = v[0][k%10-1]+"надцать"; else res='четырнадцать';
}else {
var it=0;
for (; k > 0; i++,it++){
m = k % 10;
if (m != 0){
if(it==3) {
i=0;
if(m!=1) {
res=v[i][m - 1] +' '+ tsv[m-1] + ' ' + res;
}else{
res='одна '+ tsv[m-1] + ' ' + res;
}
} else {
res = v[i][m - 1] + ' ' + res;
}
}
k=parseInt(k/10);
}
}
res=res.substring(0,1).toUpperCase()+res.substring(1)+' грн. ';
if(a[1]) res+=a[1]+' коп.'; else res+='00 коп.';
return res;
}
Выбирай.
I'm learning to live...
|