How do I convert a positive number to negative in Delphi?

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

number := -abs(number)

Let n be your number and the formula for n-(n*2) = -n


from what I know there is no function for that. you can make

if yourvariable > 0 then
    yourvariable := -yourvariable;

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

Tags:

Numbers

Delphi