how come 0 wont appear at end of decimal place


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: how come 0 wont appear at end of decimal place

Hybrid View

  1. #1
    Join Date
    Aug 2005
    Posts
    10

    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
    Posts
    635
    numerical primitives remove trailing zeros.

    http://forums.devx.com/showthread.php?t=145986

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

    Code:
    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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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