Results 1 to 7 of 7

Thread: [solved] converting to float prob

  1. #1

    Thread Starter
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112

    [solved] converting to float prob

    PHP Code:
    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...
    Last edited by ayan; Jun 1st, 2004 at 02:25 AM.

  2. #2

  3. #3

    Thread Starter
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    how can i be stupid. sorry for bothers... and oh... thankx

  4. #4

    Thread Starter
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    just one more thing... how do i do something like
    PHP Code:
    printf("%.3f",x); 
    in java... thanx again...

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Look at the classes in java.text
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6

    Thread Starter
    Lively Member ayan's Avatar
    Join Date
    Jan 2004
    Posts
    112
    got it. assuming the parsed string.
    PHP Code:
    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...
    Last edited by ayan; Jun 1st, 2004 at 02:24 AM.

  7. #7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width