Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Number Converter Application for Mitrais Coding Test

This document is a supplementary material for the source code attached in this e-mail. The
application is a console app which take user’s text input and then process it as appropriate. The
algorithm is as follows:

1. Take text input from user


2. Validate user’s input. Validation includes checking if the input is proper decimal number,
and whether it exceeds the maximum value the application can process (as of now it
supports Septillion numbers)
3. Separate the Leading Digit and Decimal Digit from the input. This is done by splitting the
input text based on the decimal separator point. I tried using pure decimal calculation to do
this, but the application did not pass my unit tests, due to it rounding the decimal places at
very high number, making the last decimal numbers treated as if they are not significant
numbers.
4. Check the leading digit if the number is in the Septillion range, if yes, then check the
Number Converter Dictionary to convert the Septillion number (1 – 999 Septillion). Add
“Septillion” to the end of the number. The dictionary contains three groups of numbers:
ones (1, 2, 3, etc.), teens (11, 12, 13, etc), and tens (10, 20, 30, etc.). The dictionary contains
28 entries. Divide the number by 1 Septillion, continue the process with the remainder.
5. Repeat Step 4 with the remainder for other number ranges (Sextillion, Quintillion,
Quadrillion, Trillion, Billion, Million, Thousand, Hundreds, Tens, Ones), until the number has
no remainder.
6. Repeat Step 4 and 5 for the decimal digit.
7. Print the converted number.

I’m choosing Decimal as the number data type to support a bigger amount of number. Even though
it supposedly has slower performance than other data type (like double, float, or long), the testing
shows that the performance cost is not significant for this type of operation. I also decided to
minimize string manipulation to reduce performance and memory cost, especially in
loops/iterations, that’s why I chose to use this approach, which mostly use Decimal calculations to
obtain the desired value.

You might also like