Last active
December 29, 2015 18:19
-
-
Save CliffordAnderson/7709717 to your computer and use it in GitHub Desktop.
Converts an integer to a corresponding sequence of words
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
(:~ | |
: Converts an integer to a corresponding sequence of words | |
: @author Clifford Anderson | |
: @version 1.0 | |
: | |
:) | |
(: This function is adapted from a function by Nelson Wells :) | |
(: http://nelsonwells.net/2012/03/convert-an-integer-to-a-sequence-of-digits-in-xquery/ :) | |
declare function local:number-to-seq($num as xs:integer) as xs:integer* | |
{ | |
if($num gt 9) then | |
( | |
local:number-to-seq(xs:integer(fn:floor($num div 10))), | |
xs:integer(fn:floor($num mod 10)) | |
) | |
else | |
$num | |
}; | |
declare function local:int-to-string($num as xs:integer) as xs:string* { | |
for $item in local:number-to-seq($num) | |
return | |
switch($item) | |
case 0 return "zero" | |
case 1 return "one" | |
case 2 return "two" | |
case 3 return "three" | |
case 4 return "four" | |
case 5 return "five" | |
case 6 return "six" | |
case 7 return "seven" | |
case 8 return "eight" | |
case 9 return "nine" | |
default return "NAN" | |
}; | |
local:int-to-string(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment