(value: string, exception = true)
| 15 | export const MAX_INTEGER = 2147483647; |
| 16 | export const MIN_INTEGER = -2147483648; |
| 17 | |
| 18 | export function toInteger(value: string, exception = true): number { |
| 19 | if (value.endsWith("-")) { |
| 20 | value = "-" + value.substring(0, value.length - 1); |
| 21 | } |
| 22 | |
| 23 | if (DIGITS.test(value) === false) { |
| 24 | if (value.trim().length === 0) { |
| 25 | value = "0"; |
| 26 | } else if (exception === true) { |
| 27 | throwError("CX_SY_CONVERSION_NO_NUMBER"); |
| 28 | } else { |
| 29 | throw new Error("CONVT_NO_NUMBER"); |
| 30 | } |
| 31 | } |
| 32 | return roundHalfAwayFromZero(parseFloat(value)); |
| 33 | } |
| 34 | |
| 35 | // ABAP rounds a half away from zero when a float is moved to an integer, |
no test coverage detected