cancel
Showing results for 
Search instead for 
Did you mean: 

Interpret dot character (decimal separator) as a comma.

Former Member
0 Kudos

Hello,

I created a WebDynpro Java Application wich is to be used by a large number of users who type massive quantities of numbers with decimal digits. I need to interpret the "." (dot) character as a "," (comma), when the key of the numeric keyboard is pressed.

I heard something about changing the language of the Portal (or setting the Locale property) but I don't know if this could be the right solution.

Someone suggested I could use an automator software like "AutoHotKey" which is a simple keyboard mapping program but I think it isn't the right solution, because of the nature of web application.

Any Idea?!

Thank's in advance

Enrico

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

I don't think there's an available active listener for WebDynpro Java on runtime. The actual requirement is for you to recognize "." entries as "," real time? I think even as you set the locale of your portal, it would still be recognized as a "." -- and will not be replaced real-time. If there was such a function/listener to do that (as in desktop java applications) - it would be coded in the WebDynpro Java and not with the Portal configuration.

So I guess, the only way to change that is a post-process method to convert these.

Other web applications that's heavy on javacripting can do this and it would be a nice enhancement for the WD API. But the actual scope it can address would be limited. But its a nice to have, still.

Others, do correct me if I'm wrong though.

Regards,

Jan

Former Member
0 Kudos

Hi Jan,

the actual requirement is:

1) write a price (euro) into an inputField using the "right" numeric keyboard (decimal price, i.e.: u20AC 153.45.... look at the "." instead of ","!);

2) if the user writes the price using numeric keyboard, so he types the "." key, I could leave "." on the screen and do the interpretation ("." -> ",") just after pushing the "Save" button (because I know the difficulties of catching the interpretation in real time!).

Even if I decided to do the interpretation programmatically into the "Save" button code, I would find a big problem because of the unknowing about cases like this:

- 154.78 ---> 154,78 (OK)

- 154.789,45 ---> ???

Note: the attribute linked to the inputField has a decimal type.

I'm going mad!

Former Member
0 Kudos

Hi,

Your first requirement can be solved easily but first you will have to change the context attribute types to String. For setting the values in the input fields simple write:


BigDecimal n = new BigDecimal("154789.45"); // no need of putting thousands seperators
/**
 * You can replace locale GERMANY to the default locale
 * or to the locale of the currently logged in user or to
 * some other country.
 */
NumberFormat f = NumberFormat.getCurrencyInstance(Locale.GERMANY);

String formattedCost = f.format(n);
//Set formattedCost to the context

Your second requirement looks trivial to me but I could be totally wrong. Given a number string "154.789,45" entered by the user you can replace all grouping separators with nothing and all decimal separator with ".". Then the input string will change to "154789.45". Now if you want commas as grouping separators then format this using the US locale. Here is a sample implementation:


String s = "154.789,45"; // read it from user input
//You can use either GERMANY or the current locale
DecimalFormatSymbols symbol = new DecimalFormatSymbols(Locale.GERMANY);

s = s.replaceAll("\\" + String.valueOf(symbol.getGroupingSeparator()), "");
s = s.replaceAll("\\" + String.valueOf(symbol.getDecimalSeparator()), "\\.");

/**
 * s is now "154789.45". If you want  "154,789.45" pass s to the code provided 
 * in the first part of the reply.
 */

Let me know if my assumption is wrong.

Regards,

Satyajit