Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


 

Java Tutorials

Core Java
JSP
Servlet
JDBC
Hibernate
Struts 1
Struts 2
JSF
Spring
J2EE
J2ME
Web Services
Ajax
Dojo
MySQL
Latest Comments
Null pointer excep
swap program faile
hi.........
very good
navigaton mobile
  All Comments...
 

 

 
Struts Tutorials
*Stuts TOC
*Apache Struts Introduction
* Struts Controller
* Struts Action Class
* Struts ActionFrom Class
* Using Struts HTML Tags
*Struts Validator Framework    
*Client Side Address Validation    
*Struts Tiles
*tiles-defs.xml
*Struts DynaActionForm
*Struts File Upload
*Struts DataSource
*AGGREGATING ACTIONS
*Internationalization
Struts Resources
*Struts Books
*Struts Articles
*Struts Frameworks
*Struts IDE
*Struts Alternative
*Struts Links
*Struts Presentations
*Struts Projects
*Struts Software
*Struts Reference
*Struts Resources
*Other Struts Tutorial
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Java Java Conversion Convert Number To Words

User Comments
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl
  Blink   Furl   Simpy   Y! MyWeb 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

13 comments so far (post your own) View All Comments Latest 10 Comments:

I want program to convert number to word,word to number,binary to hex, hex to binary,binary to octal & octal to binary

Posted by poonam on Sunday, 02.1.09 @ 00:10am | #84367

This is a buggy code..I posted the correct code..which i don't think was approved and posted on this page..

Posted by Raj on Tuesday, 09.30.08 @ 02:28am | #80786

public class NumberToWords{
static final String[] Number1 = {""," Hundred"};
static final String[] Number2 = {"","One","Two", "Three","Four","Five", " Six"," Seven", "Eight"," Nine","Ten" };
static final String[] Number3 = {"", "Ten", "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy", "Eighty","Ninety"};
static final String[] Number4 = {"", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"};

String number(int number){
String str;
if (number % 100 < 10){
str = Number2[number % 100];
number /= 100;
}
else{
if( (number % 10) == 0){
return Number3[number / 10];
}
else{
if((number % 10) < 10){
str = Number3[number / 10];
number /=10;
}else{
str = Number2[number % 10];
number /= 10;
}
if (number == 0) return str ;
return str + " " + Number2[number] ;
}
}
if (number == 0) return str;
return Number2[number] + "hundred" + str;
}

private String convert(int number) {

if(number < 0 || number > 999)
return "Invalid Number - Should be (0-999)";

if (number == 0){
return "zero";
}
String pre = "";
String str1 = "";
int i = 0;
if( (number > 10 && number < 19)){
return Number4[ number % 10];
}else{
do {
int n = number % 100;
if (n != 0){
String s = number(n);
str1 = s + Number1[i] + " " + str1;
}
i++;
number /= 100;
}
while (number > 0);
}

return (pre + str1).trim();
}
public static void main(String[] args) {
NumberToWords num = new NumberToWords();
System.out.println("words is :=" + num.convert(13));
System.out.println("words is :=" + num.convert(200));
System.out.println("words is :=" + num.convert(999));
System.out.println("words is :=" + num.convert(10));
System.out.println("words is :=" + num.convert(179));
System.out.println("words is :=" + num.convert(44));
System.out.println("words is :=" + num.convert(900));
System.out.println("words is :=" + num.convert(9221));
}
}

Posted by Raj on Thursday, 09.25.08 @ 02:51am | #80678

import java.util.HashMap;

public class NumberToWords{
static final String[] Number1 = {""," Hundred"};
static final String[] Number2 = {"","One","Two", "Three","Four","Five", " Six"," Seven", "Eight"," Nine","Ten" };

static HashMap<Integer,String> numHash = new HashMap<Integer,String> ();

String number(int number){
String str;
if (number % 100 < 10){
str = Number2[number % 100];
number /= 100;
}
else{

if( (number % 10) == 0){
return Number2[number / 10] + " zero";
}
else{
str = Number2[number % 10];
number /= 10;
if (number == 0) return str ;
return Number2[number] + " " + str;
}
}
if (number == 0) return str;
return Number2[number] + "hundred" + str;
}

private void setHash(){
numHash.put(11, "Eleven");
numHash.put(12, "Twelve");
numHash.put(13, "Thirteen");
numHash.put(14, "Fourteen");
numHash.put(15, "Fifteen");
numHash.put(16, "Sixteen");
numHash.put(17, "Seventeen");
numHash.put(18, "Eighteen");
numHash.put(19, "Nineteen");
}
private String convert(int number) {

if(number < 0 || number > 999)
return "Invalid Number - Should be (0-999)";

if (number == 0){
return "zero";
}
String pre = "";
String str1 = "";
int i = 0;
if( (number > 10 && number < 19)){
return numHash.get(number);
}else{
do {
int n = number % 100;
if (n != 0){
String s = number(n);
str1 = s + Number1[i] + str1;
}
i++;
number /= 100;
}
while (number > 0);
}

return (pre + str1).trim();
}
public static void main(String[] args) {
NumberToWords num = new NumberToWords();
num.setHash();
System.out.println("words is :=" + num.convert(10));
System.out.println("words is :=" + num.convert(200));
System.out.println("words is :=" + num.convert(999));
System.out.println("words is :=" + num.convert(20));
System.out.println("words is :=" + num.convert(179));
System.out.println("words is :=" + num.convert(44));
System.out.println("words is :=" + num.convert(-12));
System.out.println("words is :=" + num.convert(9221));
}
}

Posted by Raj on Thursday, 09.25.08 @ 01:03am | #80677

public class NumberToWords{
static final String[] Number1 = {""," Hundred"};
static final String[] Number2 = {"","One","Two", "Three","Four","Five",
" Six"," Seven", "Eight"," Nine","Ten" };
String number(int number){
String str;
if (number % 100 < 10){
str = Number2[number % 100];
number /= 100;
}
else{

if( (number % 10) == 0){
return Number2[number / 10] + " zero";
}
else{
str = Number2[number % 10];
number /= 10;
if (number == 0) return str ;
return Number2[number] + " " + str;
}

}

if (number == 0) return str;
return Number2[number] + "hundred" + str;
}
public String convert(int number) {
if (number == 0){
return "zero";
}
String pre = "";
String str1 = "";
int i = 0;
do {
int n = number % 100;
if (n != 0){
String s = number(n);
str1 = s + Number1[i] + str1;
}
i++;
number /= 100;
}
while (number > 0);
return (pre + str1).trim();
}
public static void main(String[] args) {
NumberToWords num = new NumberToWords();
System.out.println("words is :=" + num.convert(13));
System.out.println("words is :=" + num.convert(70));
System.out.println("words is :=" + num.convert(999));
System.out.println("words is :=" + num.convert(20));
}
}

Posted by Raj on Thursday, 09.25.08 @ 00:15am | #80675

In the above solution
else {
str= Number2[number % 5];
number /= 5;
}

should be replaced by

else {
str= Number2[number % 10];
number /= 10;
if (number == 0) return str;
return Number2[number] + str;
}

The program does not handle case for 20, 30, 40 etc..

Posted by Raj on Thursday, 09.25.08 @ 00:04am | #80674

that is great but the problem here is user's input is required, and it has to convert from 0 to 20,000. but our teacher say if we can do it up to 100,000 he will give whoever does that a high grade. i don't know why with the program that i did it has error, if i type 1015 it will show one thousand tenfive fifteen. ANd out teacher says we have to use SWITCH

Posted by kinderprogrammer on Monday, 09.15.08 @ 16:30pm | #79579

send me fast

Posted by prashant vyas on Saturday, 05.31.08 @ 11:11am | #61540

I Want The Code For Number To Word ConVersion Using JavaScript

Posted by sasikumar on Monday, 05.19.08 @ 14:50pm | #60444

hi,
how can convert the rupees into word.
Rupees could be more than million as well asd it may contain paise.

for example : 58234453434.50

with regards,
gopi

Posted by gopimaharajan on Friday, 03.7.08 @ 18:43pm | #51853

Input an integer number: 32767
Thirty two thousand seven hundred sixty seven

Posted by Flynn on Tuesday, 02.12.08 @ 06:50am | #47965

how to convert number to word..

Input number: 123
Output in words: One hundred twenty three

Posted by ronie on Monday, 12.10.07 @ 13:00pm | #41718

hello just want to ask how to make a program that will input a number and convert it to word maximum of 2 gigits only.. thank you.

Posted by rose on Sunday, 10.7.07 @ 05:31am | #32054

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Back to Tutorial

 

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.