Hello:
I am writing a small program to convert temperature from Fahrenheit to Centigrade. I cannot figure out why I keep getting 0.00 for the Centigrade temperature output. Also, I cannot figure out how to get the F degree symbol before or after the temp. I know in JOptionPane the char = 176 is the code for it but im not sure how to code it into the program. If someone could show me how and also give me some insight why my program keeps saying 0.00 for Centigrade temp on the output that would be great!
import javax.swing.JOptionPane; import java.text.DecimalFormat; public class tempConversion { public static void main(String[] args) { String newDecimal; String newDecimal1; String fTemp; double cTemp; double centiGrade; double fahrenHeit; double finalC; fTemp = JOptionPane.showInputDialog("Please enter a temperature in F: "); fahrenHeit = Double.parseDouble(fTemp); cTemp = (5 / 9) * (fahrenHeit - 32); DecimalFormat formatter = new DecimalFormat("#0.00"); newDecimal = (formatter.format(fahrenHeit)); newDecimal1 = (formatter.format(cTemp)); JOptionPane.showMessageDialog(null, "Current temp: " + newDecimal + " F\nCurrent temp: " + newDecimal1 + " C"); } }
--- Update ---
Okay I figured out the Degree symbol!(String DEGREE = "\u00b0") phew... now only if i can get the correct output!