File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Float / Double format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Float / Double format" Watch "Float / Double format" New topic

Float / Double format

Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
How can I format the output of a float or a double number using the public void println() method


f = 3.151416123f;


I want to see:

% 3.15

Only with two numbers, is this posible?

Does it works like C's fprintf("%2f"); ??? or something?

Any answer would be apreciate

Thanks Zkr Ryz.

Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
This works:

It returns

Hope this helps, Zkr.
Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
It did Art, thanks!!!
I agree. Here's the link:
subject: Float / Double format
It's not a secret anymore!