Developing an XML Web Service Using Visual Studio 2005 - Brief explanation of the “Number to Words” XML Web Service (Page 2 of 6 )
The XML web service, which we are going to develop now, simply accepts a number (of type “long”) and converts it to words. Putting it into plain language, if we send “345,” the XML web-service returns the result as “Three hundred forty five.” Once we host this XML Web Service, we can access it in any application of any platform using any language, even remotely!
Let us come to the discussion of the inner workings of the “Number to Words” Web service. Even though the main method is “NumberToWords,” the heart (or processing) of the entire XML web service is divided into four “private” methods as follows:
“ConvertToWords” checks number of places (or digits) in the number and chunks the number based on hundreds, thousands, and so forth. The chunked parts of the number are forwarded to “Process3DigitNumber” (for processing only three digit numbers). The “Process3DigitNumber” may forward further to “Process2DigitNumber” (for processing only two digit numbers) or “ProcessSingleDigitNumber” based on the argument it received.
At the moment, “ConvertToWords” can chunk the number to a maximum of hundreds of trillions. The maximum number could be 999,999,999,999,999 (or 999 trillions). But, there always exists a chance of extensibility (say quadrillion, quintillion, and so on). To extend further, you can simply modify and rearrange the “arrays” I declared within “ConvertToWords.”