Revision 10067 trunk/libraries/libIverUtiles/src/com/iver/utiles/stringNumberUtilities/StringNumberUtilities.java
StringNumberUtilities.java | ||
---|---|---|
54 | 54 |
* @return A boolean value |
55 | 55 |
*/ |
56 | 56 |
public static boolean isNumber(String word) { |
57 |
return (isNaturalNumber(word) || isIntegerNumber(word) || isRealNumber(word));
|
|
57 |
return isExponentialRealNumber(word);
|
|
58 | 58 |
} |
59 | 59 |
|
60 | 60 |
/** |
... | ... | |
93 | 93 |
/** |
94 | 94 |
* Returns true if the word is an integer number; else returns false |
95 | 95 |
* |
96 |
* If it's a natural number, it's an integer number |
|
97 |
* |
|
96 | 98 |
* @param word An string |
97 | 99 |
* @return A boolean value |
98 | 100 |
*/ |
... | ... | |
114 | 116 |
/** |
115 | 117 |
* Returns true if the word is a real number; else returns false |
116 | 118 |
* It's supposed that '.' is the symbol for separate integer from decimal part |
117 |
* |
|
119 |
* |
|
120 |
* If it's a natural or integer, it's a real number |
|
121 |
* |
|
118 | 122 |
* @param word An string |
119 | 123 |
* @return A boolean value |
120 | 124 |
*/ |
... | ... | |
157 | 161 |
|
158 | 162 |
|
159 | 163 |
/** |
160 |
* Returns true if the word is a real number; else returns false |
|
161 |
* It's supposed that '.' is the symbol for separate integer from decimal part |
|
164 |
* Returns true if the word is a real number with or without the 'E' (or 'e') symbol for the exponent; else returns false |
|
165 |
* It's supposed that '.' is the symbol for separate integer from decimal part, in the base and the exponent of the number |
|
166 |
* |
|
167 |
* If it's a natural, integer or real number, it's an exponential real number |
|
162 | 168 |
* |
163 | 169 |
* @param word An string |
164 | 170 |
* @return A boolean value |
... | ... | |
180 | 186 |
// Analize the word |
181 | 187 |
int i = 0; |
182 | 188 |
// for (int i = 0; i < word.length(); i++) { |
183 |
while ((Character.toUpperCase(word.charAt(i)) != 'E') && (i < word.length())) {
|
|
189 |
while ((i < word.length()) && (Character.toUpperCase(word.charAt(i)) != 'E')) {
|
|
184 | 190 |
switch (word.charAt(i)) { |
185 | 191 |
case '0': case '1': case '2': case '3': case '4': |
186 | 192 |
case '5': case '6': case '7': case '8': case '9': |
... | ... | |
201 | 207 |
i++; |
202 | 208 |
} |
203 | 209 |
|
210 |
if (i == word.length()) |
|
211 |
return true; |
|
212 |
|
|
204 | 213 |
numberOfPoints = 0; |
214 |
|
|
215 |
// Jump the symbol E |
|
216 |
i++; |
|
217 |
|
|
218 |
if (i == word.length()) |
|
219 |
return false; |
|
205 | 220 |
|
206 | 221 |
// Try to remove the sign of the number |
207 | 222 |
if ((word.charAt(i) == '-') || (word.charAt(i) == '+')) |
208 |
word = word.substring(i, word.length()); |
|
223 |
word = word.substring(++i, word.length());
|
|
209 | 224 |
|
225 |
if (word.length() == 0) |
|
226 |
return false; |
|
227 |
|
|
210 | 228 |
while (i < word.length()) { |
211 | 229 |
switch (word.charAt(i)) { |
212 | 230 |
case '0': case '1': case '2': case '3': case '4': |
... | ... | |
229 | 247 |
|
230 | 248 |
return true; |
231 | 249 |
} |
232 |
} |
|
250 |
} |
Also available in: Unified diff