cancel
Showing results for 
Search instead for 
Did you mean: 

Custom thousand separator for decimal values.

Former Member
0 Kudos

Hello esperts,

I have a a WD app with a decimal context attribute, I have already a Simple Type that formats the decimal so the thousand separator is a coma (,) and the decimal separator is the dot (.)

I want to know if it is possible to change the thousand separator to dot and the decimal separator to comma without changing the user's language. Or even use whatever character I want to be the thousand separator e.g. @ | ¬ whithout changing the data type (decimal).

Thanx in advance.

JV

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Jesus,

I am also looking for similar solution. Did you find the solution?

Regards,

Anand

Former Member
0 Kudos

You can use a string together with the DecimalFormatSymbols class

See [Customizing Formats|http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html]

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Jesus

>Or even use whatever character I want to be the thousand separator e.g. @ | ¬ whithout changing the data type (decimal).

If you want to be able to change dynamically the format and do not want to have many simple types for the purpose I'll suggest you the following. Create new String calculated attribute for the purpose. Put your custom formatting logic in getter. Put an opposite logic to setter.

Getter: convert decimal to string.

Setter: parse string to decimal.

BR, Siarhei

Former Member
0 Kudos

Hi Siarhei,

I dont want to use calculated fields, nor strings because I need the values of the decimal attribute. I will be desplaying these decimal values through a table and sorting functionality is a must. So as you should know, if I have 1, 2, 3, 20 and 100 and convert them to string, on sort it will be incorrect because of string sorting ( 1, 100, 2, 20 and 3).

Basically my requirement is to be able to change the decimal presentation without changing the user's locale or language. I don't know if that's possible.

Say, I select an option on my application that says "comma separated thousands", the decimal values will be presented this way ###,###,###,###.00 or when the user selects the option "dot separated thousands", the decimal values will be presented like this ###.###.###.###,00. I already tried to format the last reprersentation but I get java.lang.IllegalArgumentException: Malformed pattern. I have already checked the DecimalFormat API, so I know the pattern is incorrect, still I'm looking if by chance I'm forgeting something else to do in order the application to work as I spect.

Thanks!

JV

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Jesus

Try to modify the simple type on the fly. For example, something like this:

IWDAttributeInfo attrInfo;
// get attribute info...
...
DdTypeNumber numType = (DdTypeNumber) attrInfo.getModifiableSimpleType();
// set new format pattern
numType.setPattern(<pattern>);
// apply the pattern
numType.setFormatter();

BR, Siarhei

Former Member
0 Kudos

Hello Siarhei,

Thank you for your answer, I tried the solution you proposed but I´m getting the following exception:

java.lang.ClassCastException: com.sap.tc.webdynpro.progmodel.context.ModifiableSimpleType

What can I do? Or what am I doing wrong, check the code I implemented, it is triggered when the user changes a selection (that has the format options for choice).

	  IWDAttributeInfo attr = wdContext.getNodeInfo()
		.getAttribute(IContextElement.X_DECIMAL);
	  
	  DdTypeNumber decType = (DdTypeNumber) attr.getModifiableSimpleType();
	  
	  decType.setPattern(wdContext.currentContextElement().getDecimalOptions());
	  decType.setFormatter();

Hope you can help me out. Thanx in advance.

JV

Former Member
0 Kudos

Set a breakpoint at that line and check the class of the object return by getModifiableSimpleType().

Armin

Former Member
0 Kudos

Hi Armin,

The class returned by getModifiableSimpleType() is: com.sap.tc.webdynpro.progmodel.context.ModifiableSimpleType . As far as I can see, I can't cast ModifiableSimpleType to DdTypeNumber.

I am running out of options, I thought it would be easier to change de number format.

Any ideas, or am I doing something wrong?

Thanx in advance.

JV

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Jesus

Then try the following code:

	  IWDAttributeInfo attr = wdContext.getNodeInfo().getAttribute(IContextElement.X_DECIMAL);
	  
	  ISimpleTypeModifiable decType = attr.getModifiableSimpleType();
	  decType.setFormat(wdContext.currentContextElement().getDecimalOptions());

I'm very sorry, but I have not a chance to test a code before posting, but I believe that the new variant of code shall work.

BR, Siarhei

Former Member
0 Kudos

You can create a custom simple type based on decimal and format it however you want to.