"%.2f" format problem

String fmt = "%.2f";
outfile.write(String.format(fmt, point.core_dist));

I have got a problem. Using this format it prints out 2,0 and what I want to achieve is a decimal point so 2.0 How to solve that?
chudyksgAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:
It is eaiser to use DecimalFormat for formatting than printf.
This is the simple example:
http://www.roseindia.net/java/beginners/DecimalFormatExample.shtml


0
for_yanCommented:
This should give you what you want:

 NumberFormat formatter = new DecimalFormat("#0.0");
outfile.write(formatter.format(point.core_dist));


0
chudyksgAuthor Commented:
It didn't help. Still writing a colon instead of decimal point. Any other suggestions?
Even if i do this  System.out.println(formatter.format(2.0)); it prints out 2,0 in the console instead of 2.0
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

for_yanCommented:
What if you just print
System.out.println("2.0")

or another test

double dd = 2.05;

System.out.println("" + dd);

Do all these print comma istead of dot ?
0
chudyksgAuthor Commented:
yep they both print decimal point

This code:

 NumberFormat formatter = new DecimalFormat("#0.0");
                System.out.println(formatter.format(2.0));
               
                System.out.println("2.0");
                double dd = 2.05;
                System.out.println("" + dd);

Gives the following results:
2,0
2.0
2.05
0
for_yanCommented:
That is probably something wrong with locale
0
chudyksgAuthor Commented:
what do you mean by that?
0
for_yanCommented:

Try this way:
   Locale.setDefault(Locale.US);
        NumberFormat formatter = new DecimalFormat("#0.0");
                           System.out.println(formatter.format(2.0));
       
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chudyksgAuthor Commented:
That is working. Thanks a lot. Do you know how to change the locale permanently in netbeans?
0
for_yanCommented:
I'd think taht it should read it from the system - go to Control Panel | regional Option (General tab) -
or maybe similar on different systems - and check if your system has correct Locale
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.