MCPcopy Create free account
hub / github.com/abaplint/transpiler / toInteger

Function toInteger

packages/runtime/src/types/integer.ts:17–32  ·  view source on GitHub ↗
(value: string, exception = true)

Source from the content-addressed store, hash-verified

15export const MAX_INTEGER = 2147483647;
16export const MIN_INTEGER = -2147483648;
17
18export 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,

Callers 2

eqFunction · 0.90
setMethod · 0.85

Calls 2

throwErrorFunction · 0.90
roundMethod · 0.80

Tested by

no test coverage detected