File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
Float / Double format
Zkr Ryz
Ranch Hand
Joined: Jan 04, 2001
Posts: 187
posted
Apr 23, 2001 22:42:00
0
How can I format the output of a float or a double number using the public void println() method
like:
f = 3.151416123f;
System.out.println(f);
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
posted
Apr 24, 2001 05:07:00
0
This works:
<font size="2.0"> import java.text.*; public class FormatDecimal { public static final String MASK = "0.00"; public static final float TO_FORMAT = 3.151416123F; public static void main( String[] args ) { DecimalFormat df = new DecimalFormat( MASK ); System.out.println( df.format( TO_FORMAT ) ); } }
It returns
<font size="2.0"> 3.15
Hope this helps, Zkr.
Art
Zkr Ryz
Ranch Hand
Joined: Jan 04, 2001
Posts: 187
posted
Apr 24, 2001 12:15:00
0
It did Art, thanks!!!
I agree. Here's the link:
http://zeroturnaround.com/jrebel/download
subject: Float / Double format
Similar Threads
convert double to float ?
converting float to double
Wrapper class
Overloading confusion
float variable
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter