Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

formatting a double variable

Status
Not open for further replies.

papaboy2

MIS
Jan 28, 2003
52
0
0
PH
hi, i want to ask how can i format a double variable so that it will hava a 4 decimal point to the right? thank you very much!

here is my code:(LastValue is a double variable)
LastValue = Float.parseFloat(CalcNumber.getText());
LastValue += FirstValue;
CalcNumber.setText(Double.toString(LastValue));
 
Hi,

Have a look at "NumberFormatter" or "NumberFormat" class. I don't have much experience with it but it might solve your problem.
 
Code:
// I discover a precision problem
import java.text.DecimalFormat;
import java.text.NumberFormat;
class ro2
      {
       public static void main(String args[])
              {
               double input = 12.05666;
               double input2 = 43.43345;
               String outputString1, outputString2;
               DecimalFormat myDecFormat = new DecimalFormat("########0.0000");               

               System.out.println("Result "+myDecFormat.format(input));                System.out.println("ResultB "+myDecFormat.format(input2)); 
              }
      }
 
thank you very much! i appreciate ur help, just one more question how can i avoid my textfield not to receive the focus and not show the cursor it it? thank you again!
 
myJtextField.requestFocus();
if you use this method and it does not work, please post your runnable code.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top