DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2005

    how come 0 wont appear at end of decimal place

    Can someone please help me why JAVA wont display the zero at the end of the decimal place. for instance,

    double A = 6.000

    by right A = 6.000

    However, when i execute this System.out.println(A);

    output of A = 6.0

    Can someone tell me how do i keep the the value to 6.000. Not possible for me to use decimalformat class because I need variable A to be a double.

    I write a program that round off value to 2 decimal places, However, it will only appear as 20.0 when the value is suppose to be 20.00, or show only 5.6 when it suppose to be 5.60. can someone please tell me how to solve this problem. thank in advance!

  2. #2
    Join Date
    Mar 2004
    numerical primitives remove trailing zeros.


  3. #3
    Join Date
    Aug 2005
    To format to two decimal places:

    int number = 2.55510;
    NumberFormat nf = new DecimalFormat();
    nf.setMaximumFractionDigits(2) ;
    String numberFormatted = nf.format(number);
    System.out.println( numberFormatted );
    Remember to import java.text.*

    For more help, www.NeedProgrammingHelp.com

Similar Threads

  1. Packed Data(Comp-3, etc)
    By Marcos in forum VB Classic
    Replies: 3
    Last Post: 01-25-2006, 11:18 AM
  2. Help with VB code
    By Ana in forum VB Classic
    Replies: 5
    Last Post: 04-27-2005, 03:16 PM
  3. Re: App Object (fixes)
    By Rob Teixeira in forum .NET
    Replies: 129
    Last Post: 06-06-2002, 05:23 AM
  4. Usercontrol's never been terminated
    By Rattagarn V. in forum VB Classic
    Replies: 5
    Last Post: 10-09-2000, 07:36 AM
  5. How do I detect an FTP timeout?
    By Julian Milano in forum VB Classic
    Replies: 2
    Last Post: 08-11-2000, 12:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.