473,425 Members | 1,668 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

Converting numbers to spellings (eg, 10 to ten)

How to convert numerals like 123 into spellings like one hundred twenty three?
Nov 29 '07 #1
3 2041
debasisdas
8,127 Expert 4TB
Welcome to TSDN.

Feel free to post questions in the related forum only by choosing from under the blue bar on the top of your page.

Can you kindly post what you have tried so far for reference of our experts.

Please follow the posting guidelines in every new post/reply.

Regards

Debasis
Nov 29 '07 #2
It is exactly the same assignement my Professor gave me 2 months ago during the course("ANSI C Programming");for example we were assigned a 9 digits number( e.g. 987123456) and we had to cast it into "nine hundred eightyseven MILLION one hundred tewnty three thousand four hundred fifty six".
I have to say that it took me the whole day to design a proper algorithm.
I really would like you to focus on one fact:look how patterns repeat;you basically have to design an algorithm to translate just a 3 digit group,and apply it iteratively to the entire input,following the tipical Divide et Impera paradygm.
Take a look at some useful functions in the <string.h> ANSI C header;strcat should be the one wich suits most this kind of problem.
Nov 29 '07 #3
Hi,
I am just adding to what MarshMallow has written.

1. Accept the number as a string.
2. Find its length
3. Send the nos in threes to a function "numword()" which prints words for numbers from zero to 999.
4.Depending on the length print "thousands" or "millons" or "billions" or ....

5. Function numword() should accept the three digits as a 3 element string.
6. Take the first element. Use it as index in a Case/switch statement to print words for nos from 1 to 9.Then print "hundred".
6. If second element is 1 use another case/switch statement with third element as index to print from eleven to nineteen.
7. If second element is not 1, take the third element (units) and use it in the previous switch-case statement to print words for numbers from 1 to 9.
8. Take the second element and use it in another switch/case statement to print words for twenty to ninety.
9. Use your own logic to tackle zeroes in both numword() and in the main program.

It will be interesting to extend the program for decimals also.
Nov 29 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sverre Bakke | last post by:
Hi I am using the base_convert() function to convert numbers between binary, hexadecimal, decimal, etc... It works great, but I have problems converting numbers with .'s Like this number: ...
7
by: MeganTSU | last post by:
Hey yall! I am trying to get this program finished for class.... It says that you are suppposed to write a program that will display a check formatted out put (the output looks like a check). I got...
0
by: shara | last post by:
Hello there, Can anybody help me with this.I'm working on VB macros and i came across a situation where i have to convert numbers to column alphabets i.e....
4
by: chopin | last post by:
I am using Visual Basic for Applications to convert a number to the same number of single quotes. For example, if the number is 6, then I need 6 single quotes in succession. The logic is easy: ...
1
missinglinq
by: missinglinq | last post by:
From the Access Object Dialog Box click on "Modules" Click on new to make a new module Copy then paste the following code into the new module: Function SayNo(ByVal N As Currency) As String ...
2
by: Rohit111111 | last post by:
Hello all, I want to convert number into there equivalent words like if number is 567342 than result is Five Lac sixty seven thousand three hundred and fourty two. I am using asp.net c# Thanks...
4
by: josha13 | last post by:
I am very new to C++ and I am trying to figure out how to convert a number to a string (even in the simplest case such as #include <iostream> #include <sstream> using namespace std; int main...
9
by: WyattM | last post by:
i have been trying to get this code to work but keep getting errors. what am I doing wrong? the errors that I am getting are: 'Public Property Left() As Integer' has no parameters and its return...
5
by: byte8bits | last post by:
Here's how I'm doing this right now, It's a bit slow. I've just got the code working. I was wondering if there is a more efficient way of doing this... simple example from interactive Python: ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.