Results 1 to 3 of 3
  1. #1
    playwin2 is offline Member
    Join Date
    Aug 2008
    Posts
    58
    Rep Power
    0

    Red face [SOLVED] Problem hadling number(money) > 214,74,83,647.99

    Hello,
    How do I suppose to handle number(money) > 214,74,83,647.99

    Presently doing following:-
    but it gives numberformat errors for value exceding 214,74,83,647.99 :(
    Java Code:
    private static void doIt(int num)
    	{
            if (num >= 1000000000)
            {
                String temp = "" + num;
                System.out.println("temp :" + temp);
                //break it...
                String temp2 = temp.substring(0, (temp.length() - 7));
                String temp3 = temp.substring(temp.length()-7);
                int num1 = Integer.parseInt(temp3);
                num = Integer.parseInt(temp2);
                //...
                System.out.println("temp After break:" + temp2);
                System.out.println("Num now:" + num);
                System.out.println("Rem Num now:" + num1);
                //' do stuffs
                //....
            }
    	}
    Input ....
    Java Code:
    BufferedReader br = new BufferedReader(
    				new InputStreamReader(System.in));
    		
    		String input = "";
    		
    		while(true){
    		try
    		{
    			System.out.print("\nEnter number (Type \'END\' to exit) :");
    			input = br.readLine();
    			//check exit cond...
    			if(input.equalsIgnoreCase("END"))break;
    		
    			System.out.println("You Entered: " + input);
    			doIt(Integer.parseInt(input));
    		}
    		catch(Exception e)
    		{
    			e.printStackTrace();
    		}}

    Thanks for any clue...
    Last edited by playwin2; 10-14-2008 at 08:08 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    Default

    Please post the full text of the error message with your question.
    It has the line number where the error occured.

    What data type are you storing the value in? What is the maximum value that the data type will hold?
    For example a byte can only hold 256 different values.

  3. #3
    playwin2 is offline Member
    Join Date
    Aug 2008
    Posts
    58
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    What data type are you storing the value in? What is the maximum value that the data type will hold?
    Ah! Thank you so much Norm, I just forgot int can only hold (2 to the power 31 -1).

    Ooops!

    You see, I was converting an earlier VB6 routine into Java; In VB the data type was Variant, here I'm using int, so it's turned out that I need to break the data here before converting it.

    Thanks again, :) Problem solved.

Similar Threads

  1. Using double for money is a sin
    By fishtoprecords in forum New To Java
    Replies: 3
    Last Post: 11-28-2008, 07:05 AM
  2. Money Conversion - Proofreading pls?
    By javanewbie in forum New To Java
    Replies: 5
    Last Post: 08-17-2008, 01:40 PM
  3. Replies: 1
    Last Post: 08-09-2008, 12:10 PM
  4. Money to Words
    By javanewbie in forum New To Java
    Replies: 2
    Last Post: 06-30-2008, 04:27 AM
  5. Replies: 2
    Last Post: 11-11-2007, 08:07 AM

Posting Permissions

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