vijayam
asked on
How can I print a double value 0.0 to 0.00?
Hi
I am trying to print a string value to Double .But i need to print in different format..
I have used the following code
String s1 = "2"
String s2 = ".1"
Double d1 = new Double(s1);
Double d2 = new Double(s2);
System.out.println("First double"+d1+"### Second double "+d2);
Its pirnting
FirstDouble 2 ### Second double 0.1.
But i want it be printed as
d1 as 2.00 and d2 as 0.10
How can it be possible?
Thanks.
Vijaya.
I am trying to print a string value to Double .But i need to print in different format..
I have used the following code
String s1 = "2"
String s2 = ".1"
Double d1 = new Double(s1);
Double d2 = new Double(s2);
System.out.println("First double"+d1+"### Second double "+d2);
Its pirnting
FirstDouble 2 ### Second double 0.1.
But i want it be printed as
d1 as 2.00 and d2 as 0.10
How can it be possible?
Thanks.
Vijaya.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am getting the output,but it is as string but i need it as Double.
DecimalFormat df = new DecimalFormat("0.00");
FieldPosition fp = new FieldPosition (NumberFormat.INTEGER_FIEL D);
StringBuffer sb= new StringBuffer();
sb = df.format( d1 , sb, fp );
then its printing sb as 2.00
But i need it to be as Double that's why i coverted this to string and parsed..as
Double dd = new Double(sb.toString());
then its printing,same 2 again...what should i do,if i want to print 2.00 as Double object.
thanks.
Vijaya.
DecimalFormat df = new DecimalFormat("0.00");
FieldPosition fp = new FieldPosition (NumberFormat.INTEGER_FIEL
StringBuffer sb= new StringBuffer();
sb = df.format( d1 , sb, fp );
then its printing sb as 2.00
But i need it to be as Double that's why i coverted this to string and parsed..as
Double dd = new Double(sb.toString());
then its printing,same 2 again...what should i do,if i want to print 2.00 as Double object.
thanks.
Vijaya.
The representation of an object, when materialized as a String, has a varying relation to its binary content. In the case of numbers, or object wrappers of numbers, the binary form is, and should be, distinct and different
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
s1 = nf.format(d1.doubleValue()