Charlie J.

asked • 08/28/17

expressing numbers in words and viceversa

SuperStrict
Rem
Question A01
In banking, processing bankchecks are an important routine used everyday
With thousands of check to process, banking systems have ways to automate
the writing the credit amount in English.

Implement the function
- Answer:String (aInteger:Int)

Arguments:
- "aInteger" stores a number that can be translated with a range
from +/- 2 billion

return:string
- the string containing the english representation

example:
if aInteger = 2034515
then the return result should be
"Two Million thirty four thousand five hundred and fifteen"
End Rem

Function Answer:String (aInteger:Int)

End Function

1 Expert Answer

By:

Andy C. answered • 09/03/17

Tutor
4.9 (27)

Math/Physics Tutor

Andy C.

This is a working java application for your problem.
Wyzant does not allow Java to be posted.
 
Not sure which programming language you are using.
The only thing I can offer is to rewrite it in VIsual Basic
which looks most similar to the language you are using.
 
Note that the integer data type cannot store values in the billions.
The max integer is 32767. You MUST use the LONG or LONG INT
data type to store values that large.
 
You will need an array of 10 long integers to store the digits as you process them.
In a for loop, divide the amount by 1 billion and store the result in the first array block,
storing the remainder. Next divide that remainder by 100 million, storing the result
in the second array block, keeping that remainder. Divide by 10 million, storing the
result in the 3rd array block, keeping the remainder. etc. etc. etc.  The for loop in
DoConvert() does this using the integer division operator / and the mod operator %
 
You will need two helping procedures to display the result. A single routine is not enough.
One routine returns the strings 'ONE", "TWO", THREE, etc when passed a digit 1,2,3,...,9
It is called GetTextDigit
 
The second helping routine converts a three digit number to text:
  Example: 534 return Five Hundred Thirty Four
                 46 returns fourty six
    It is called Get3DigitStr. it is used to convert the millions, the thousands,
  and then the units groups of 3 digits to text
 
DoConvert call DisplayResult which builds the output buffer based on the digits in the array.
 
You can copy and paste the source code into a text document.
Name it AmountToText.java
Use javac to compile at the DOS prompt:    javac AmountToText.java
 
Use java to run:   java AmountToText
 
Optionally you can specify your input on the command line.
 
As in your example:  java AmountToText 2034515
 
 
 
 
Report

09/04/17

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.