Skip to main content

NEG

Returns the inverse sign of a number.

Synopsis

NEG(number)

Arguments

number An expression that resolves to a number or a numeric string.

Description

The NEG function returns the inverse sign of a number. For example, NEG(-1) returns 1, and NEG(1) returns -1. NEG removes multiple signs and leading and trailing zeros from number. A string is parsed as a number until a non-numeric character is encountered. Thus “7dwarves” is parsed as 7. If number is the empty string or a non-numeric value, NEG returns 0 (zero).

The NEG function inverts the sign of a number: negative numbers become positive and positive numbers become negative. The ABS function gives the absolute value of a number: all numbers become positive.

You can use the NEGS function to invert the sign for each element of a dynamic array.

Examples

The following example uses the NEG function to invert the sign of a number:

PRINT NEG(0050.300);  ! Returns -50.3
PRINT NEG(-50.3);     ! Returns 50.3
PRINT NEG(+++50.3);   ! Returns -50.3
PRINT NEG(0);         ! Returns 0
PRINT NEG(-0);        ! Returns 0

See Also

FeedbackOpens in a new tab