From: Matt S. <Mat...@wh...> - 2007-01-08 18:48:02
|
Right now the TextToNumberConverter is configurable with these properties: Converter textConverter (specifies how one textual format is converted into another, e.g. String -> StringBuffer) Converter numberConverter (specifies how one number is converted into another, e.g. -> Double -> Long) char[] symbolsToIgnore = { '(', ')', ' ', '\t', '\r', '\n' } Based on whether symbolsToIgnore includes opening and closing parantheses the converter decides whether or not values in parantheses should be negated. In fact, there is even an internal transient property called negateValuesInParantheses that is set based on the values in symbolsToIgnore. I think this behavior is backwards. It is not at all obvious that in order to turn on the ability to make "(1000)" become -1000L I need to set the symbolsToIgnore to the char[] array { ' ', '\t', '\r', '\n' }. I would like to get rid of this public symbolsToIgnore array and add new configuration properties as follows: handlePercentages (default true) - determines whether text value ending in % should be divided by 100 when converted to a number. so, 100% becomes 1 and 10% becomes .1 ignoreWhitespace (default true) - automatically remove all whitespace before attempting the conversion. this would be useful if, for example, a user enters " 3" instead of "3" in a form on accident. negateValuesInParantheses (default true) - if a number begins and ends with (), automatically treat it as a negative number. if this value is set to false, an exception would most likely be thrown when converting the text to a number (unless there's some locale where they use ( to be the thousands separator or something, lol) Like it? Hate it? I need this ASAP for work so I am planning on coding it today. Matt |