How do I convert a positive Integer to a negative with Delphi? I know you could use ABS(int)
to convert a negative to a positive, but I need it to convert positive to negative.
from what I know there is no function for that. you can make
if yourvariable > 0 then
yourvariable := -yourvariable;
If you want to be absolutely sure to get a negative result (or zero), use
number := -abs(number)
Ehhh... Too late but number := number * -1;
would work too, but this change the symbol of any number, negative to positive and backwards... To ensure a negative value go with @Mef Answer
EDIT: even later, but number := 0 - number;
would work too... This just reverses the symbol as well
Let n
be your number and the formula for n-(n*2) = -n
Simple this is how I think it can be solved.. in python though
>>>num = -234
-234
>>>num *= -1
234
>>>num
234
Correct me if am wrong
来源:https://stackoverflow.com/questions/9968707/how-do-i-convert-a-positive-number-to-negative