cancel
Showing results for 
Search instead for 
Did you mean: 

Convert a String to Decimal Format in European format

Former Member
0 Kudos

Hi Experts,

I am having a string as a context type for a input field, where the user can enter the Price, I need to convert the same into European format "###.###,00", I am using this below code to convert the string to decimal format

User will enter the input as 10 as it needs to be converted into 10,00. Also, 1000 which has to be converted as 1.000,00


String Str1 = wdContext.currentvn_temptable.getVa_TempUnitPrice();
Locale mylocale  = Locale.GERMAN;
String pattern="###.###,00";				
NumberFormat nf = NumberFormat.getNumberInstance(mylocale);
DecimalFormat df = (DecimalFormat)nf;
df.applyPattern(pattern);
String output = df.format(Str1);
wdComponentAPI.getMessageManager().reportSuccess("Unit Price" + " " + pattern + " " + output);

When I execute the above code, i am getting an error called "Malformed Pattern ###.###,00"

Please let me know, how to convert a String to Quantity in European format

Thanks & Regards,

Palani

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello!

Try to change your pattern to this one


Locale mylocale  = Locale.GERMAN;
String pattern = "#,#00.00";				
NumberFormat nf = NumberFormat.getNumberInstance(mylocale);
DecimalFormat df = (DecimalFormat)nf;
df.applyPattern(pattern);
String output = df.format(1111111.222);

Pattern has an influence on number of digits between separators, but you have to use ',' for grouping and '.' for decimal. Character values for separators correspond to your Locale object.

Thanks, Mikhail