class CFListen implements ActionListener{
public void actionPerformed(ActionEvent event){
TempConversion convert = new TempConversion(Double.parseDouble(userInput.getText()) );
theOutput.setText("C to F : " + String.format("%.2f",convert.CtoF()));
}
}
Cant get "string.format" to work properly
Page 1 of 13 Replies - 414 Views - Last Post: 05 June 2011 - 08:54 PM
#1
Cant get "string.format" to work properly
Posted 02 June 2011 - 06:37 PM
Hello all, this is my first post
im pretty new to java, cant get String.format to work properly, it tells me that the String is not applicable for the arguments(string, double)...any thoughts?
Replies To: Cant get "string.format" to work properly
#2
Re: Cant get "string.format" to work properly
Posted 02 June 2011 - 07:20 PM
Is there something else i can use other than String.format to display 3 digits after the decimal point?
#3
Re: Cant get "string.format" to work properly
Posted 02 June 2011 - 09:17 PM
The DecimalFormat class will do the job
http://download.orac...imalFormat.html
but what's wrong with String.format() ?
If you want 3 digits you will need %.3f not %.2f and are you sure convert.CtoF() returns a float/double ?
http://download.orac...imalFormat.html
but what's wrong with String.format() ?
If you want 3 digits you will need %.3f not %.2f and are you sure convert.CtoF() returns a float/double ?
#4
Re: Cant get "string.format" to work properly
Posted 05 June 2011 - 08:54 PM
That was the problem, it wasn't returning a float/double. Thanks for the help
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|