Code:
unit NrToWords;
interface
// Unit NrToWords
// Doel: zet een geheel getal van 0 tot 10^18 ( 1 triljoen)
// om naar woord uitspraak in het Nederlands
//
// Voorbeeld : 123456 levert op
// honderd drientwintig duizend vierhonderd zesenvijftig
// Schrijfwijze ontleend aan boek
// Handboek voor de communicatie van de wiskunde
// van P.L. Brinkman uitg. Agon Elsevier 1974
// isbn: 90 10 10463 X
//
// Datum: 1 oktober 2003
// Versie: 1.0
// Auteur: C.F.W. Loomans
//
// Bugs: Onbekend
// Beperkingen:
// 1. Het bovenste deel van het int64 bereik
// kan niet worden omgezet
// 2. Getallen als 3800 worden omgezet naar
// drieduizend achthonderd en niet achtendertighonderd
//
// Copyright : C.F.W. Loomans
// Patent rechten: Pending
//
// Bij deze is deze software geplaatst in het Public Domain
// Ieder mag het gebruiken en naar zijn wensen aanpassen
// Engelse versie zie onderaan de unit
// for English version look down after the unit
function GetalNaarWoorden( Getal : int64 ):string ;
implementation
const
Woorden20 : array[0..20] of string =
( 'nul','een','twee','drie','vier','vijf',
'zes','zeven','acht','negen','tien',
'elf','twaalf','dertien','veertien','vijftien',
'zestien','zeventien','achtien','negentien','twintig');
Woorden100 : array[0..10] of string =
('nul','tien','twintig','dertig','veertig','vijftig',
'zestig','zeventig','tachtig','negentig','honderd' );
WoordenMachten1000 : array[0..6] of string =
( 'een','duizend','miljoen','miljard','biljoen',
'duizend biljoen','triljoen' );
WaardenMacht1000: array[0..6] of int64 =
( 1,
1000,
1000000,
1000000000,
1000000000000,
1000000000000000,
1000000000000000000 );
// getallen tot twintig krijgen een speciale behandeling
function Gw20( Getal : int64 ):string;
begin
Result:=Woorden20[Getal];
end;
// getallen tot honderd zijn ook wat eigenaardig
function Gw100( Getal : int64 ):string;
var t,e:int64;
begin
if Getal<=20 then
Result:=Gw20(Getal)
else begin
t:=Getal div 10;
e:=Getal mod 10;
if e>0 then Result:=Woorden20[e]+'en';
Result:=Result+Woorden100[t];
end;
end;
// getallen tot 1000 apart behandelen
function Gw1000( Getal : int64 ):string;
var h,t:int64;
begin
Result:='';
if Getal<=100 then
Result:=Gw100(Getal)
else begin
h:= Getal div 100;
t:= Getal mod 100;
if h>1 then
Result:=Gw20(h);
Result:=Result+Woorden100[10];
if t>0 then
Result:=Result+' '+Gw100(t);
end;
end;
// Let op
// Macht wil zeggen Macht van 1000
function GwMeerDanDuizend( const Getal : int64 ; const Macht : int64 ):string;
var g1,g2:int64;
begin
Result:='';
if Getal<1000 then
Result:=Gw1000(Getal)
else begin
if Getal<WaardenMacht1000[Macht-1] then
Result:=GwMeerDanDuizend(Getal,Macht-1)
else begin
g1:= Getal div WaardenMacht1000[Macht-1]; // veelvouden (1-1000)
g2:= Getal mod WaardenMacht1000[Macht-1]; // wat er over is
if (g1=1000) and (g2=0) then
Result:=WoordenMachten1000[Macht] // exact aantal
else begin
if g1>1 then
Result:=Gw1000(g1); // aantal (max 1000)
Result:=Result+WoordenMachten1000[Macht-1];
if g2>0 then
Result:=Result+' '+GwMeerDanDuizend(g2,Macht-1) // wat over is
end;
end;
end;
end;
function GetalNaarWoorden( Getal : int64 ):string ;
begin
Result:=GwMeerDanDuizend(Getal,6)
end;
end.
// Unit NrToWords
// Purpose: To convert a number to a string in which the
// numberwords are used to represent the number
// The numberwords are in Dutch
//
// Example : 123456 becomes
// honderd drieentwintig duizend vierhonderd zesenvijftig
//
// Date: 1 oktober 2003
// Version: 1.0
// Author: C.F.W. Loomans
//
// Bugs: Unknown
// Limitations: The upper part of the int64 range can not be
// converted
//
// Copyright : C.F.W. Loomans
// Patent rights: Pending
//
// This software is placed in the public domain.
// Anyone can use it or change it to his own needs
Bookmarks