Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: I Want To Apply Currency Format To My 2 Dimensional Array?

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I Want To Apply Currency Format To My 2 Dimensional Array?

    I want to apply currency format to all the columns to my 2 dimensional array except the first column?
    this code prints my array on the console with a currency format, How do i code it so it won't print currency format to my first column but on every thing else??
    PHP Code:
    for (int i 0salesArray.lengthi++)
            {
                for (
    int j 0salesArray[i].lengthj++)
                    
    System.out.print(currency.format(salesArray[i][j]));
                
                
    System.out.print("\n");
            } 


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I Want To Apply Currency Format To My 2 Dimensional Array?

    Use an if statement to detect when the index is in the first column and use a different print() statement.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: I Want To Apply Currency Format To My 2 Dimensional Array?

    Or run j from 1 to whatever.

  4. #4
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I Want To Apply Currency Format To My 2 Dimensional Array?

    if I run j from 1 [i][1] that will just print out my array without the first column, I want to keep the column just not currency formatted like the others?
    using an if statement like Norm suggested would work but for instance this accomplishes my goal it prints the first column in numberformat and the others in currecny format the issue is column 2,3, and 4 completely disappear i only get column 1 and 2 to appear is their something wroing with the way i set up the If statement??:
    PHP Code:
    if (== 0)
                    {
                    
    System.out.print( "    " number.format(salesArray[i][j]));
                    }
                   
    System.out.print( "    " currency.format(salesArray[i][1])); 

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I Want To Apply Currency Format To My 2 Dimensional Array?

    issue is column 2,3, and 4 completely disappear i only get column 1 and 2
    Look at the print statement and see why it doesn't print any but the values at index 0 and index 1
    The index in the code does not index past those two values.

    Look at using an else statement to control the second print statement.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Mar 2013
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I Want To Apply Currency Format To My 2 Dimensional Array?

    Quote Originally Posted by Norm View Post
    Look at the print statement and see why it doesn't print any but the values at index 0 and index 1
    The index in the code does not index past those two values.

    Look at using an else statement to control the second print statement.
    I tried that but all it does is duplicate the first column on to other columns so they all have the same values of the first column it works in a sense that it display all columns though, i'll continue tinkering with it.

    --- Update ---

    I got it to work I used and if statement like before, but instead of and else statement I used another for loop and it worked like a charm
    Thanks for all your help guys!

Similar Threads

  1. need two dimensional array help..
    By mmagyar14 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 16th, 2013, 09:11 PM
  2. Converting Two dimensional array into an Array list
    By NewbieJavaProgrammer in forum Object Oriented Programming
    Replies: 11
    Last Post: September 29th, 2012, 04:23 PM
  3. Help with looking through a two-dimensional array.
    By aesguitar in forum Algorithms & Recursion
    Replies: 14
    Last Post: June 1st, 2012, 11:10 AM
  4. Help with one-dimensional array
    By brandon66 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: April 26th, 2012, 04:59 PM
  5. How to apply RowFilter in JXTreeTable
    By skmoorthy02 in forum AWT / Java Swing
    Replies: 2
    Last Post: January 27th, 2011, 12:49 PM