Weird Problem w/ DecimalFormat

C

Cliff

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
 
T

Thomas Weidenfeller

Cliff said:
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
 
A

Andy Fish

Thomas Weidenfeller said:
Sounds like it works as advertised.


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)
 
F

Fred

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.
 
F

Fred

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.
 
R

Roedy Green

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top