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)
| 1022 | * @throws RuntimeException If number is null or a non-finite number. |
| 1023 | */ |
| 1024 | private static String numberToString(Number number) { |
| 1025 | if (number == null) { |
| 1026 | throw new RuntimeException("Null pointer"); |
| 1027 | } |
| 1028 | testValidity(number); |
| 1029 | |
| 1030 | // Shave off trailing zeros and decimal point, if possible. |
| 1031 | |
| 1032 | String string = number.toString(); |
| 1033 | if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && |
| 1034 | string.indexOf('E') < 0) { |
| 1035 | while (string.endsWith("0")) { |
| 1036 | string = string.substring(0, string.length() - 1); |
| 1037 | } |
| 1038 | if (string.endsWith(".")) { |
| 1039 | string = string.substring(0, string.length() - 1); |
| 1040 | } |
| 1041 | } |
| 1042 | return string; |
| 1043 | } |
| 1044 | |
| 1045 | |
| 1046 | /** |
no test coverage detected