# Thread: how to change numbers into word numbers?

1. Member
Join Date
Oct 2011
Posts
31
Rep Power
0

## how to change numbers into word numbers?

Sorry if my title is ambiguous. I don't know how to explain it in a short sentence :D.

So if i input some random integer:1003 as a string.

How can i get the output to look like this:

1,003

and

one thousand and three.

2. ## Re: how to change numbers into word numbers?

For the first one? Look at the NumberFormat class.

For the second one? How do you do that in your head?

3. Senior Member
Join Date
Nov 2010
Posts
210
Rep Power
7

## Re: how to change numbers into word numbers?

Here's something to start you off:

Java Code:
```final String[] nums0To19 = {"zero", "one", "two", /* ... */ "nineteen"};
public void speakNum(int num) {
System.out.println(nums0To19[num]);
}```
Modify that to deal with tens, hundreds, thousands and so forth.

4. ## Re: how to change numbers into word numbers?

Also look at division to get the number of 1000's for example.

5. Member
Join Date
Oct 2011
Posts
31
Rep Power
0

## Re: how to change numbers into word numbers?

okay thanks for the suggestions so far. Will try it out right now

6. Member
Join Date
Oct 2011
Posts
31
Rep Power
0

## Re: how to change numbers into word numbers?

okay i'm still stuck. Right now, i have the digits in a character array box.

eg. if the input was 123,

it would be held in a char [] number = (1,2,3) box.

i can't figure how how to put seperators with the number format class, and i can't figure how how to tell the size of each digit. (I got it to print one two three for the input 123).

7. ## Re: how to change numbers into word numbers?

In what format are you getting the input? As a String: "123" or as an int: 123 or as three chars: '1', '2', '3'?
What statement(s) are you using to get the input?

8. Member
Join Date
Nov 2011
Posts
65
Rep Power
0

## Re: how to change numbers into word numbers?

Many replys here though i've noticed noone gave you a definative answer to exactly what your looking for;

best described I think I would say you are trying to convert a integer into a numeric string and also asking how to format an integer to a string in words

I'll try to look into what your trying to do and see if I can find anything, personnaly i've never found a need to convert a number into the word equivalent-- best of luck

9. ## Re: how to change numbers into word numbers?

Originally Posted by akeni
i have the digits in a character array
Leave it as an int (best option) or a String.

10. ## Re: how to change numbers into word numbers?

Originally Posted by kevinn205
noone gave you a definative answer to exactly what your looking for;
If you mean no-one spoonfed them the answer then no that is not how it works. They were given plenty of tips and hints on how to do it themselves. Not only will they have done the work themselves (and not cheated) but they will also learn from the experience.

11. Member
Join Date
Oct 2011
Posts
31
Rep Power
0

## Re: how to change numbers into word numbers?

it was a string input, but i returned it into a character. It cannot be in an int type because it the number can be greater than int's capacity.

12. Member
Join Date
Nov 2011
Posts
2
Rep Power
0

## Re: how to change numbers into word numbers?

Hi,

import java.text.DecimalFormat;
public class ConvertIntToString {
public static void main(String[] args) {

String aString = "1003";
int aInt= Integer.parseInt(aString);
System.out.println(aInt);
DecimalFormat df = new DecimalFormat("#,##0;(#,##0)");
System.out.println(df.format(aInt));
}
}

Thanks
Lakshmi M

13. Member
Join Date
Nov 2011
Posts
2
Rep Power
0

## Re: how to change numbers into word numbers?

Hi,

Below is the program to convert an integer into words.

[ spoonfeeding deleted - Jos ]

Regards
Lakshmi M
Last edited by JosAH; 11-17-2011 at 10:45 AM. Reason: spoonfeeding ...

14. Member
Join Date
Oct 2011
Posts
31
Rep Power
0

## Re: how to change numbers into word numbers?

thanks for the help, i'm still figuring it out. Almost got it though :)

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•