Formatting this number

Question Description

I’m working on a Programming question and need guidance to help me study.

i would like this tiny bit of help.

i built this little program that calculates stuff(unimportant what it calculates).

but sometimes when its dividing or multiplying big numbers, it displays it in the scientific notification.

like it should display: 10000000(10 million)

but it displays: 1.0E7.

how can i fix this? i dont want it to display it in the scientific notifitcation.


[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);[/CODE]

Student has agreed that all tutoring, explanations, and answers provided by the tutor will be used to help in the learning process and in accordance with Studypool's honor code & terms of service.

Final Answer

public static String formatDecimal(double d, int precision)
String myformat = "###,###,###,###,##0";
if (precision == 0)
//System.out.println("OK Decimal is: " + d);
DecimalFormat df = new DecimalFormat(myformat);
return df.format(d);

myformat = "###,###,###,###,##0.";

for(int x= 0; x < precision; x++)
myformat = myformat + "0";

DecimalFormat df = new DecimalFormat(myformat);
return df.format(d);
public static String round_my_float(float f, int places)
String precision = "";
if (places == 0)
precision = "0";
precision = "0.";
for(int y = 0; y < places; y++)
precision += "0";

//DecimalFormat df=new DecimalFormat("0.000");
DecimalFormat df=new DecimalFormat(precision);
return df.format(f);

Codorna (2)
Cornell University

I was on a very tight deadline but thanks to Studypool I was able to deliver my assignment on time.

The tutor was pretty knowledgeable, efficient and polite. Great service!

I did not know how to approach this question, Studypool helped me a lot.


Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors