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
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.
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
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!
deependeroracle (January 10th, 2012)
can u tell me what is void in java ? what are modifiers and what System.out.print(); returns
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!
deependeroracle (January 11th, 2012)