Format Number in Textfield with 1000 separator
editOrJan 12 2013 — edited Jan 13 2013Hi,
I'm entering numeric values (Doubles) into a textfield. Since those numbers can be pretty large I'd like to have a 1000-separator for orientation purposes. This separator should update every time I modify the textfield.
I tried to format the number in the changeListener using the class DecimalFormat. But when adding separators this leads to 2 problems:
1. The Cursor position does not stay at the place you whould expect it to be (since separators are added)
2. When editing (using the "del"-key every time this key stroke deletes a separator nothing happens. This seems clear since the code does the following: Delete separator -> Change -> format number (which n fact is not changed when deleting the separator) --> separator is added again (which brings me to the beginning again).
This leads to the result, that the number is only deleted until the next separator when holding the "delete"-key, which is pretty uncomfortable.
Unfortunately I couldn't find a solution that works for me. I thought this might be a common problem and can be solved a more elegant way, maybe completely different way?
Any help much appreciated
Michael
Edited by: editOr on 12.01.2013 13:01