# Spelling out numbers in words (Dutch)

Here’s an algorithm (in pseudo-code) for spelling out numbers in Dutch words (e.g. convert `123` to `"honderddrieëntwintig"`):

``````-- spell out an integer number in words (Dutch)
function numberToWordsDutch(number)
var result, iteration, iterationText, hundreds, hundredsText

if number = 0
return "nul"
end

result ← ""
iteration ← 1

-- iterate per 3 digits (starting with last)
while number > 0
hundreds ← number modulo 1000 -- e.g. 23456 → 456
number ← floor(number / 1000) -- e.g. 23456 → 23

if hundreds > 0
-- 3 digits to text
hundredsText ← getHundredsText(hundreds)
if iteration > 1
-- duizend, miljoen, …
iterationText ← getIterationText(iteration)
hundredsText ← hundredsText + iterationText
if hundredsText = "eenduizend "
hundredsText ← "duizend "
end
end

result ← hundredsText + result
end

iteration ← iteration + 1
end

return trim(result)
end

function getHundredsText(number)
var result, hundreds, tens

result ← ""

hundreds ← floor(number / 100) -- e.g. 456 → 4
if hundreds > 0
number ← number modulo 100 -- e.g. 456 → 56
if hundreds > 1
result ← result + getLessThanTwentyText(hundreds)
end
result ← result + "honderd"
end

if number > 0
if hundreds > 0 and number ≤ 12
result ← result + "en"
end

if number < 20
-- < 20 ⇒ look up
result ← result + getLessThanTwentyText(number)
else
tens ← floor(number / 10) -- e.g. 42 → 4
number ← number modulo 10 -- e.g. 42 → 2

if number > 0
-- een, twee, drie, …
result ← result + getLessThanTwentyText(number)
if number = 2 or number = 3
result ← result + "ën"
else
result ← result + "en"
end
end

-- dertig, veertig, …
result ← result + getTensText(tens)
end
end

return result
end

function getLessThanTwentyText(number)
case number
when 1 return "een"
when 2 return "twee"
when 3 return "drie"
when 4 return "vier"
when 5 return "vijf"
when 6 return "zes"
when 7 return "zeven"
when 8 return "acht"
when 9 return "negen"
when 10 return "tien"
when 11 return "elf"
when 12 return "twaalf"
when 13 return "dertien"
when 14 return "veertien"
when 15 return "vijftien"
when 16 return "zestien"
when 17 return "zeventien"
when 18 return "achttien"
when 19 return "negentien"
otherwise error
end
end

function getTensText(tens)
case tens
when 2 return "twintig"
when 3 return "dertig"
when 4 return "veertig"
when 5 return "vijftig"
when 6 return "zestig"
when 7 return "zeventig"
when 8 return "tachtig"
when 9 return "negentig"
otherwise error
end
end

function getIterationText(iteration)
case iteration
when 1 return ""
when 2 return "duizend "
when 3 return " miljoen "
when 4 return " miljard "
when 5 return " biljoen "
when 6 return " biljard "
when 7 return " triljoen "
when 8 return " triljard "
otherwise return " ??? "
end
end``````