Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: regarding floating point

  1. #1
    Member
    Join Date
    Jan 2012
    Posts
    57
    My Mood
    Fine
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default regarding floating point

    when i write float a=2; a=a+2; in C language then the output is 4.000000 ... but when i write the same code in java float a = 2F;
    a=a+2;
    then i got 4.0; why i m not getting the six zeros after the decimal like in c language
    thanks
    deepender sharma


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: regarding floating point

    Why not 7 zeros, or 8, or a hundred? How a number is displayed (especially trailing zeros) isn't really a "this language does it this way, why not this language?" issue. It might even be system dependent.

    But anyway, what you're looking for is either the printf() function: PrintStream (Java Platform SE 6)

    Or the DecimalFormat class: DecimalFormat (Java Platform SE 6)
    Last edited by KevinWorkman; January 9th, 2012 at 11:33 AM.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    deependeroracle (January 10th, 2012)

  4. #3
    Member
    Join Date
    Jan 2012
    Posts
    57
    My Mood
    Fine
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Default Re: regarding floating point

    can u tell me what is void in java ? what are modifiers and what System.out.print(); returns

  5. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: regarding floating point

    Quote Originally Posted by deependeroracle View Post
    can u tell me what is void in java ? what are modifiers and what System.out.print(); returns
    Have you looked through the basic tutorials? Have you looked at the API? If you have more questions that are unrelated to your original, I suggest you ask them in their own thread after reading the link in my signature on asking questions the smart way.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. The Following User Says Thank You to KevinWorkman For This Useful Post:

    deependeroracle (January 11th, 2012)

Similar Threads

  1. Replies: 2
    Last Post: November 30th, 2011, 07:35 PM
  2. Declaring floating point number depending on an if statement
    By Keys767 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 11th, 2011, 01:50 PM
  3. Rounding long or floating numbers, or longs for that matter.
    By SPACE MONKEY in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 28th, 2011, 12:32 AM
  4. using Eclipse and every program gives the errorr with floating numbers
    By Neera in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 30th, 2010, 12:11 PM
  5. how do i use point 3d?
    By antrax in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 6th, 2010, 05:13 PM