Hi, to everyone.‎

My program to make program to write the application the input ‎a dollar amount to be printed on a cheque, and then prints the ‎amount with eleven position number are available for printing ‎the cheque. And need to run the word equivalent of the cheque ‎amount e.g.: the amount 123.30 should be written
One hundred twenty three dollars and thirty cents ‎

My problem I don't know how to make to run the number to ‎the word equivalent of the cheque amount. Like this
The amount 123.30 should be written as One hundred twenty three dollars and thirty cents ‎

‎ This is my code:‎

import javax.swing.*;‎
‎ * <p>Title: </p>‎
‎ * <p>Description: </p>‎
‎ * <p>Copyright: Copyright (c) 2005</p>‎
‎ * <p>Company: </p>‎
‎ * @author not attributable‎
‎ * @version 1.0‎
‎ */‎
public class Cheque
‎       {‎
‎        public static void main (String [] args)‎
‎        {‎
‎          String Q = JOptionPane.showInputDialog(null, "Please ‎Enter the Account..");‎

‎          int l;‎
‎          int nn=0;‎
‎          int t=0;‎
‎         for (int x=1 ; x<=Q.length() ; x++)‎
‎         {‎
‎           if (Q.length() < 12) {‎
‎             l = Q.length();‎
‎             t = l - 12;‎
‎             nn = t * ( -1);‎
‎           }‎
‎       }‎
‎         System.out.println(  " "+Q +"$"+" t The Cheque amount ‎‎" );‎
‎        System.out.println( " " + nn+ " t The positon number");‎
‎            }‎
‎        }‎

can anyone tell me how can i do that.Thank you,

Recommended Answers

All 2 Replies

Simple global constants should do.

Take $123.30.

1. First you need to separate the dollars and the cents using the substring method of the String class (see code below).

2. How do you convert a hundreds digit? Just put "Hundred" afterwards:

1xx = > One Hundred xx

3. How do you convert a tens digit? This one is harder.

If the tens digit is 1, then it is easiest to just handle every possible case (11-19) in a big if statement.


If the tens digit is a 2 then its always "Twenty" followed by the rest.

21 => "Twenty One"


If the tens digit is a 9 then its always "Ninety" followed by the rest.

97 => "Ninety Seven"

4. How do you obtain the digits? After separating the dollars from the cents, use the charAt method of the String class.

Run the code below for a simple example of obtaining the digits:

class NumToWord 
	public static void main(String[] a)
		//define string
		String text = "123.30";
		//find position of decimal in text
		int decimalPos = text.indexOf(".");
		//get text before decimal
		String dollars = text.substring(0, decimalPos);
		//get text after decimal
		String cents = text.substring(decimalPos+1);
		//get last pos in dollars text
		int lastPosInDollars = dollars.length()-1;
		//get hundreds digit
		char hundredsDigit = dollars.charAt(lastPosInDollars-2);
		//get tens digit
		char tensDigit = dollars.charAt(lastPosInDollars-1);
		//get ones digit
		char onesDigit = dollars.charAt(lastPosInDollars-0);
		System.out.println ("The ones digit is " + onesDigit);
		System.out.println ("The tens digit is " + tensDigit);
		System.out.println ("The hundreds digit is " + hundredsDigit);

:?: For more help, www.NeedProgrammingHelp.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.