Produce a string from a Number. @param number A Number @return A String. @throws RuntimeException If number is null or a non-finite number.
(Number number)
| 980 | * @throws RuntimeException If number is null or a non-finite number. |
| 981 | */ |
| 982 | private static String numberToString(Number number) { |
| 983 | if (number == null) { |
| 984 | throw new RuntimeException("Null pointer"); |
| 985 | } |
| 986 | testValidity(number); |
| 987 | |
| 988 | // Shave off trailing zeros and decimal point, if possible. |
| 989 | |
| 990 | String string = number.toString(); |
| 991 | if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && |
| 992 | string.indexOf('E') < 0) { |
| 993 | while (string.endsWith("0")) { |
| 994 | string = string.substring(0, string.length() - 1); |
| 995 | } |
| 996 | if (string.endsWith(".")) { |
| 997 | string = string.substring(0, string.length() - 1); |
| 998 | } |
| 999 | } |
| 1000 | return string; |
| 1001 | } |
| 1002 | |
| 1003 | |
| 1004 | /** |
no test coverage detected