Weird Problem w/ DecimalFormat

Discussion in 'Java' started by Cliff, May 11, 2004.

  1. Cliff

    Cliff Guest

    The following code snippet:

    static DecimalFormat nf=new DecimalFormat("#####.00");
    System.out.println(nf.format(1000.10));

    sometimes stops working properly and instead of seeing 1000.10 I see 1000,10
    (note the comma). I can't for the life of me figure out what is going on...
    I'm using Java 1.3.1 on a Sun workstation.

    Any ideas?

    Cliff
     
    Cliff, May 11, 2004
    #1
    1. Advertising

  2. Cliff wrote:
    > The following code snippet:
    >
    > static DecimalFormat nf=new DecimalFormat("#####.00");
    > System.out.println(nf.format(1000.10));
    >
    > sometimes stops working properly


    Sounds like it works as advertised.

    > and instead of seeing 1000.10 I see 1000,10
    > (note the comma). I can't for the life of me figure out what is going on...
    > I'm using Java 1.3.1 on a Sun workstation.


    Check the settings of your locale (LANG and LC_ environment variables,
    etc.). Not everyone in the world uses the '.' as the decimal delimiter.

    /Thomas
     
    Thomas Weidenfeller, May 11, 2004
    #2
    1. Advertising

  3. Cliff

    Andy Fish Guest

    "Thomas Weidenfeller" <> wrote in message
    news:c7q002$fvf$...
    > Cliff wrote:
    > > The following code snippet:
    > >
    > > static DecimalFormat nf=new DecimalFormat("#####.00");
    > > System.out.println(nf.format(1000.10));
    > >
    > > sometimes stops working properly

    >
    > Sounds like it works as advertised.
    >
    > > and instead of seeing 1000.10 I see 1000,10
    > > (note the comma). I can't for the life of me figure out what is going

    on...
    > > I'm using Java 1.3.1 on a Sun workstation.

    >
    > Check the settings of your locale (LANG and LC_ environment variables,
    > etc.). Not everyone in the world uses the '.' as the decimal delimiter.


    I think you need to define "sometimes". I would be very surprised if it
    behaves this way intermittently in a consistent environment. Once you have
    figured out the difference in environment you have the answer.

    Often these kind of things work one way when you run it in the development
    environment or when loggged on interactively, but a different way when you
    install it in the services control panel (NT), or have it run as an rc
    script (*x)



    >
    > /Thomas
     
    Andy Fish, May 11, 2004
    #3
  4. Cliff

    Fred Guest

    I may be totally off the mark here, but I believe that you need to adjust
    your location settings in your operating system. You have your system
    number format set to the European standard where they use a comma instead of
    a period (ie: 1000,10 instead of 1000.10). That would explain the comma
    coming up instead of the period.

    Hope this helps,

    Fred.

    "Cliff" <> wrote in message
    news:TIXnc.12164$Lm3.10664@lakeread04...
    > The following code snippet:
    >
    > static DecimalFormat nf=new DecimalFormat("#####.00");
    > System.out.println(nf.format(1000.10));
    >
    > sometimes stops working properly and instead of seeing 1000.10 I see

    1000,10
    > (note the comma). I can't for the life of me figure out what is going

    on...
    > I'm using Java 1.3.1 on a Sun workstation.
    >
    > Any ideas?
    >
    > Cliff
    >
    >
     
    Fred, May 12, 2004
    #4
  5. Cliff

    Fred Guest

    You may need to adjust the location settings of your operating system. It
    sounds like you have your system set to the European standard where the
    comma takes the place of the period.

    Hope this helps,

    Fred.

    "Andy Fish" <> wrote in message
    news:8W0oc.41$...
    >
    > "Thomas Weidenfeller" <> wrote in message
    > news:c7q002$fvf$...
    > > Cliff wrote:
    > > > The following code snippet:
    > > >
    > > > static DecimalFormat nf=new DecimalFormat("#####.00");
    > > > System.out.println(nf.format(1000.10));
    > > >
    > > > sometimes stops working properly

    > >
    > > Sounds like it works as advertised.
    > >
    > > > and instead of seeing 1000.10 I see 1000,10
    > > > (note the comma). I can't for the life of me figure out what is going

    > on...
    > > > I'm using Java 1.3.1 on a Sun workstation.

    > >
    > > Check the settings of your locale (LANG and LC_ environment variables,
    > > etc.). Not everyone in the world uses the '.' as the decimal delimiter.

    >
    > I think you need to define "sometimes". I would be very surprised if it
    > behaves this way intermittently in a consistent environment. Once you have
    > figured out the difference in environment you have the answer.
    >
    > Often these kind of things work one way when you run it in the development
    > environment or when loggged on interactively, but a different way when you
    > install it in the services control panel (NT), or have it run as an rc
    > script (*x)
    >
    >
    >
    > >
    > > /Thomas

    >
    >
     
    Fred, May 12, 2004
    #5
  6. Cliff

    Roedy Green Guest

    On Mon, 10 May 2004 23:25:34 -0400, "Cliff" <> wrote
    or quoted :

    >sometimes stops working properly and instead of seeing 1000.10 I see 1000,10
    >(note the comma). I can't for the life of me figure out what is going on...
    >I'm using Java 1.3.1 on a Sun workstation.


    Swedes like to use commas where we use dot. Use Wassup to find out
    what you have selected for your international settings.

    see http://mindprod.com/jgloss/wassup.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, May 12, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johnny

    DecimalFormat

    Johnny, Oct 25, 2003, in forum: Java
    Replies:
    10
    Views:
    7,921
    A Dahlman
    Oct 27, 2003
  2. Timo Nentwig

    Padding for DecimalFormat?

    Timo Nentwig, Jan 5, 2004, in forum: Java
    Replies:
    3
    Views:
    4,661
    Tony Dahlman
    Feb 12, 2004
  3. Adam Lipscombe
    Replies:
    2
    Views:
    856
    Virgil Green
    Nov 29, 2004
  4. asafshec
    Replies:
    2
    Views:
    11,574
    Oliver Wong
    Oct 19, 2005
  5. harryajh

    Funny DecimalFormat problem

    harryajh, Feb 22, 2007, in forum: Java
    Replies:
    1
    Views:
    403
    Ingo R. Homann
    Feb 22, 2007
Loading...

Share This Page