3 Replies - 495 Views - Last Post: 05 June 2011 - 08:54 PM Rate Topic: -----

#1 spacegravy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-June 11

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?




 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()));
        }
    } 


Is This A Good Question/Topic? 0
  • +

Replies To: Cant get "string.format" to work properly

#2 spacegravy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-June 11

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?
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8334
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

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 ?
Was This Post Helpful? 0
  • +
  • -

#4 spacegravy11  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-June 11

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1