Click to See Complete Forum and Search --> : [solved] converting to float prob
ayan
May 31st, 2004, 01:37 AM
class Document3{
public static void main(String args[]){
String s="123.450";
System.out.println(Float.parseFloat(s));
}
}
outputs 123.45. zero(0) is gone. what am i doing wrong? thanx...
Dillinger4
May 31st, 2004, 02:08 PM
You are doing nothing wrong. 0.450 is the same as 0.45
ayan
May 31st, 2004, 08:34 PM
how can i be stupid. sorry for bothers... and oh... thankx :)
ayan
May 31st, 2004, 09:02 PM
just one more thing... how do i do something like
printf("%.3f",x);
in java... thanx again...
CornedBee
Jun 1st, 2004, 01:40 AM
Look at the classes in java.text
ayan
Jun 1st, 2004, 02:19 AM
got it. assuming the parsed string.
import java.text.*;
public class Document3{
public static void main(String args[]){
DecimalFormat df=new DecimalFormat("##0.000");
System.out.println(df.format(123.450));
}
}
thanx very much... :)
Dillinger4
Jun 1st, 2004, 07:29 AM
:thumb: Anytime
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.