2

I am trying to display 3000 as €300,0 using the code below :

String formattedString = String.format("%.2€;",3000);  
System.out.println("format: "+formattedString);

but result in force close error.

what am I missing?

1

3 Answers 3

4

I would recommend using a locale-specific currency format instead

NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.getDefault());

Better I18N that way.

Sign up to request clarification or add additional context in comments.

Comments

1

Check out the Java API: NumberFormat. It will show how to use predefined formats top achieve your goal.

Comments

0

Try something like this:

import java.text.NumberFormat;
import java.util.Locale;

Locale locale = new Locale("en", "UK");
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);//use Locale.getDefault() if you didn't know the type
System.out.println(fmt.format(100.00));

This will print: £100.00

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.