on 02-10-2010 11:10 PM
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
Jesus,
I am also looking for similar solution. Did you find the solution?
Regards,
Anand
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use a string together with the DecimalFormatSymbols class
See [Customizing Formats|http://java.sun.com/docs/books/tutorial/i18n/format/decimalFormat.html]
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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
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
You can create a custom simple type based on decimal and format it however you want to.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.