# how to change numbers into word numbers?

• 11-15-2011, 10:56 AM
akeni
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.
• 11-15-2011, 04:21 PM
KevinWorkman
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?
• 11-15-2011, 05:51 PM
Iron Lion
Re: how to change numbers into word numbers?
Here's something to start you off:

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.
• 11-15-2011, 06:32 PM
Norm
Re: how to change numbers into word numbers?
Also look at division to get the number of 1000's for example.
• 11-16-2011, 10:39 AM
akeni
Re: how to change numbers into word numbers?
okay thanks for the suggestions so far. Will try it out right now
• 11-16-2011, 11:47 PM
akeni
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).
• 11-17-2011, 12:04 AM
Norm
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?
• 11-17-2011, 12:13 AM
kevinn205
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
• 11-17-2011, 12:14 AM
Junky
Re: how to change numbers into word numbers?
Quote:

Originally Posted by akeni
i have the digits in a character array

Leave it as an int (best option) or a String.
• 11-17-2011, 12:16 AM
Junky
Re: how to change numbers into word numbers?
Quote:

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-17-2011, 08:17 AM
akeni
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.
• 11-17-2011, 08:32 AM
lakshmit
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
• 11-17-2011, 08:36 AM
lakshmit
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
• 11-18-2011, 09:46 AM
akeni
Re: how to change numbers into word numbers?
thanks for the help, i'm still figuring it out. Almost got it though :)