"%.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


for_yanCommented:
This should give you what you want:

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


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
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

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 ?
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
for_yanCommented:
That is probably something wrong with locale
chudyksgAuthor Commented:
what do you mean by that?
for_yanCommented:

Try this way:
   Locale.setDefault(Locale.US);
        NumberFormat formatter = new DecimalFormat("#0.0");
                           System.out.println(formatter.format(2.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?
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
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.