How to convert a positive number to a negative?

How to convert a positive integer to a negative with Delphi? I know that you could use ABS(int)to convert a negative value to a positive, but I need to convert it positive to negative.

+5
source share
5 answers

from what I know there is no function for this. You can do

if yourvariable > 0 then
    yourvariable := -yourvariable;
+16
source

If you want to be absolutely sure to get a negative result (or zero), use

number := -abs(number)
+37
source

Ehhh... , number := number * -1; , , ... @Mef Answer


EDIT: even later, but number := 0 - number;will work too ... It also just cancels the character

+5
source

Let it nbe your number and formula forn-(n*2) = -n

+1
source

Just so I think this can be solved .. in python, though

>>>num = -234
-234
>>>num *= -1
234
>>>num
234

Correct me if I am wrong

0
source

All Articles