Locale - European or UK number/date formats handling

Dear Support,

I wanted to use the conversion function to produce output in UK number formats, My input file contains European and UK format number system.

With the help of CloverDX support (Thank you) I have managed to work out the graph (unable to attach). It works fine for digit of 4 i.e. “12.23” (UK) or “12,23” (European) but it is not giving me output for larger numbers for example:

12,36 (European)

12.36 (UK)

1.213,45 (European)

1,213.45 (UK)

1.213.456,897 (European)

1,213,456.897 (UK)

I need all the above to product output in UK format.

Expression, I have used in the Map component

is below:

//#CTL2

function integer transform() {

$out.0.after =iif(isDecimal($in.0.before)==true, str2decimal($in.0.before,“##,##”, “en.GB”),str2decimal($in.0.before,“##.##”,“cs.CZ”));

return ALL;

}

Also, any date formats either input file contains US or UK both to UK formats as well.

Kind regards

Not sure what exactly is the problem. If just the parsing, then this “#,##0.###” should be the UK format, however, instead of passing in the format string, you can just pass empty string “” and locale. It should then take the default format/parse string for that locale.

Also, keep in mind this (from Clover docs) in case you would have numbers with spaces (formatted):

Space as group separator_ _If locale with space as group separator is used, there should be a hard space (char 160) between digits to parse the number correctly.

For formatting decimal value back to string, respecting particular locale, you can use function formatMessageWithLocale.

formatMessageWithLocale("es.ES","{0}",123456.78D);  
formatMessageWithLocale("en.GB","{0,number,###,###.##}",123456.78D);

Btw - if you are dealing with numbers/strings which may be in US or UK or other and need to convert them to decimal, you can also use conditional fail expression or try-catch block to simply attempt different conversions and just go with the one which does not fail - as checking for some specific characters to determine whether you should use US or UK or other is problematic.

decimal mydecimal;  
  
//conditional fail expression  
//if first fails, then second is attempted, then third,etc.  
  
mydecimal = str2decimal(input,"#,##0.###", "en.GB") : str2decimal(input,"##.##","cs.CZ");  
  
//the same effect, but using try-catch with potentially better control  
//over what happens if expression fails  
boolean success=false;  
try{  
   mydecimal = str2decimal(input,"#,##0.###", "en.GB");  
   success=true;  
}catch(CTLException ex){  
}  
if (!success){  
 try{  
   mydecimal = str2decimal(input,"##.##","cs.CZ");  
   success=true;  
}catch(CTLException ex){  
}  
}