Results 1 to 7 of 7
  1. #1
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    127
    Rep Power
    0

    Default i just can't fix this

    yes josAH ive tried reading the orcale docs, but i can't manage to actually make it work.
    the problem: this things caluclates numbers, but when the number caluclated gets too big, it shows the number in the scientific notificiation.

    example: 10000000(10 million)
    shows up as: 1.0E7.

    how am i going to format this number?


    Java Code:
    if(e.getSource()==b1 && box.getSelectedItem()==fish[8]){
    				String xp1 = txt1.getText();
    				long xp2 = Integer.parseInt(xp1);
    				String xp3 = txt2.getText();
    				long xp4 = Integer.parseInt(xp3);
    				long xpleft = xp4 - xp2 ;
    				long fishleft = xpleft / 350;
    				JOptionPane.showMessageDialog(null, "XP left: "+"\t"+xpleft+"\n"+box.getSelectedItem()+" left: "+"\t"+fishleft+"\n"+"\n"+"NOTE: always round these numbers."+"\n"+"example: fish left: 1,87 = fish left: 2.", "Fishing Calculator", JOptionPane.INFORMATION_MESSAGE);

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default Re: i just can't fix this

    There are no floating point numbers involved in your code so nothing will print in scientific notation. Please be accurate for once if you want help.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    127
    Rep Power
    0

    Default Re: i just can't fix this

    ehm lol there is.



    ill give you a screenshot.


  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default Re: i just can't fix this

    So you have hidden the information and not mentioned the relevant types; a very wise thing to do; have you read about the Formatter class as I have suggested in your other thread (also there was no need to open yet another thread for the same problem).

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    127
    Rep Power
    0

    Default Re: i just can't fix this

    yes i have read about the formatter class, and no i cant seem to find a way to fix this problem. because this is in a JOptionPane and the formatter i have read about, i couldnt find an example with a formatter in a JOptionPane.




  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,730
    Blog Entries
    7
    Rep Power
    21

    Default Re: i just can't fix this

    Quote Originally Posted by MR bruto View Post
    yes i have read about the formatter class, and no i cant seem to find a way to fix this problem. because this is in a JOptionPane and the formatter i have read about, i couldnt find an example with a formatter in a JOptionPane.
    Of course not; the core class library would've been a complete mess if every class should anticipate for every other class. A Formatter has nothing to do with a JOptionPane; a Formatter can produce a properly formatted String through anything that implements the Appendable interface (see the constructors for the Formatter class). If you don't supply an Appendable, it creates its own. Create a Formatter, make it format something, get the Appendable (e.g. a StringBuilder) and convert that to a String and feed it to a JOptionPane.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    MR bruto's Avatar
    MR bruto is offline Senior Member
    Join Date
    May 2013
    Location
    The Netherlands
    Posts
    127
    Rep Power
    0

    Default Re: i just can't fix this

    Quote Originally Posted by JosAH View Post
    Of course not; the core class library would've been a complete mess if every class should anticipate for every other class. A Formatter has nothing to do with a JOptionPane; a Formatter can produce a properly formatted String through anything that implements the Appendable interface (see the constructors for the Formatter class). If you don't supply an Appendable, it creates its own. Create a Formatter, make it format something, get the Appendable (e.g. a StringBuilder) and convert that to a String and feed it to a JOptionPane.

    Jos
    what i just saw was this: i have one other program like this one. (they are similar).

    it just works properly there, but in this one (in the thread) it doesn't.

    herer we have one that works properly:

    Java Code:
    if(e.getSource()==b1 && txt3.getText().equalsIgnoreCase("rocktail")){
    					String xp1 = txt1.getText();
    					int xp2 = Integer.parseInt(xp1);
    					String xp3 = txt2.getText();
    					int xp4 = Integer.parseInt(xp3);
    					int xpleft = xp4 - xp2 ;
    					int fishleft = xpleft / 13300;
    					JOptionPane.showMessageDialog(null, "XP left: "+"\t"+xpleft+"\n"+"Fishes left: "+"\t"+fishleft, "Fishing Calculator", JOptionPane.INFORMATION_MESSAGE);

    the one that puts it in scientific notification:

    Java Code:
    if(e.getSource()==b1 && box.getSelectedItem()==fish[8]){
    				String xp1 = txt1.getText();
    				int xp2 = Integer.parseInt(xp1);
    				String xp3 = txt2.getText();
    				int xp4 = Integer.parseInt(xp3);
    				double xpleft = xp4 - xp2 ;
    				double fishleft = xpleft / 350;
    				JOptionPane.showMessageDialog(null, "XP left: "+"\t"+xpleft+"\n"+box.getSelectedItem()+" left: "+"\t"+fishleft+"\n"+"\n"+"NOTE: always round these numbers."+"\n"+"example: fish left: 1,87 = fish left: 2.", "Fishing Calculator", JOptionPane.INFORMATION_MESSAGE);

Posting Permissions

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