double A,B,C,D;
Object ButtonPressed = Punch.getSource();
JConversionTables You = new JConversionTables();
if(ButtonPressed == MetricToEnglish)
{
A = Double.parseDouble(TCentimeters.getText());
B = Double.parseDouble(TMeters .getText());
C = Double.parseDouble(TKilograms .getText());
D = Double.parseDouble(TCelsius .getText());
TInches .setText("" + You.CentimetersToInches(A));
TFeet .setText("" + You.MetersToFeet (B)/>);
TPounds .setText("" + You.KilogramsToPounds (C));
TFarenheit.setText("" + You.CelsiusToFarenheit (D));
}
if(ButtonPressed == EnglishToMetric)
{
A = Double.parseDouble(TInches .getText());
B = Double.parseDouble(TFeet .getText());
C = Double.parseDouble(TPounds .getText());
D = Double.parseDouble(TFarenheit.getText());
TCentimeters.setText("" + You.InchesToCentimeters(A));
TMeters .setText("" + You.FeetToMeters (B)/>);
TKilograms .setText("" + You.PoundsToKilograms (C));
TCelsius .setText("" + You.FarenheitToCelsius (D));
}
3 Replies - 318 Views - Last Post: 05 October 2012 - 10:47 AM
#1
How would I print only two 3 decimal places here?
Posted 05 October 2012 - 10:02 AM
Hey there. I'm making a program to convert metric to imperial and I'm wondering how I would make the output have the number only extend 3 digits after the decimal point. I was thinking a substring but I'm not totally sure how to implement it here. In this bit of code the program reads what's in the metric side's textfields (meters, etc.) and puts the conversion into the imperial side's textfields. Since this is where it prints you an answer I felt this was the suitable piece to show you. If that's not the case, inform me and I'll give more. Keep in mind that the numbers BEFORE the decimal could be any size. Could be 5 numbers, could be just one. who knows. But I want to format it so the output shows the entire number before the decimal and 3 digits after the decimal. Any help would be appreciated.
Replies To: How would I print only two 3 decimal places here?
#2
Re: How would I print only two 3 decimal places here?
Posted 05 October 2012 - 10:16 AM
Check out this reference:
Formatting Numeric Print Output
Formatting Numeric Print Output
This post has been edited by rfs02: 05 October 2012 - 10:17 AM
#3
Re: How would I print only two 3 decimal places here?
Posted 05 October 2012 - 10:44 AM
rfs02, on 05 October 2012 - 10:16 AM, said:
Hmm...well I know about the printf command but I'm not sure how to use it here because the display is put into a textfield right away and displayed there instead of in a print. Is it possible in this piece of code to have it getText from the textfields, then somehow do the computation (which is in "You". As in You is my instance of JConversionTables which is where all of the actual math goes on) and format it. Once it's formatted it would be placed in the textfield?
#4
Re: How would I print only two 3 decimal places here?
Posted 05 October 2012 - 10:47 AM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|