-3

I have a small program to do and i am stuck with floating point. I want the result to be in 1 dicimle only.

this is my program

enter image description here

I want to make a floating point in both results whether i convert from F to C or C to F.

i am using JFrame, and i tried to use String.format but i doesn't work!

 private void cTFActionPerformed(java.awt.event.ActionEvent evt) {                                    
    float tempFahr = (float) ((Float.parseFloat(cTF.getText()))
            * 1.8 + 32);
    fTF.setText(tempFahr + "");
    String.format("%.1", tTF.getText());

The program is working fine, but i had a problem with the dicimles only.

Can you explain to me how to use it with JFrame ?


Edit:

we found the solution already

ΦXocę 웃 Пepeúpa ツ
  • 45,713
  • 17
  • 64
  • 91

1 Answers1

1

You are not setting the formatted value to the text field, your formatting is basically a no-op. Store the formatted value in the text field:

fTF.setText(format(tempFahr));

Replace format with anything you choose for formatting.

Community
  • 1
  • 1
Dragan Bozanovic
  • 22,362
  • 4
  • 40
  • 106