I want to find out if a specific value in a field is a Negative value or a Positive values. Examples of values: -5, 6, -44.65, 1247, -1.9 Is there a function in MS Access or code to determine this....once I know if positive or negative then I can apply correct formula to this...thanks Rosemary
Believe it or not, there is a Function designed specifically for this and is called the
Sgn() Function. The syntax is Sgn(number) and it returns a Variant(Integer) indicating the Sign of the number. If the number (or expression evaluating to a number) is greater than 0, Sgn(number) returns 1, if it is equal to 0, Sgn(number) returns 0, and if its is less than 0 Sgn(number) returns -1. A couple of examples will illustrate this Function:
- Dim MyVar1, MyVar2, MyVar3, MySign
-
MyVar1 = 12: MyVar2 = -2.4: MyVar3 = 0
-
-
MySign = Sgn(MyVar1) ' Returns 1.
-
MySign = Sgn(MyVar2) ' Returns -1.
-
MySign = Sgn(MyVar3) ' Returns 0.