Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

numbers

delphi

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.

like image 911
Tprice88 Avatar asked Apr 01 '12 22:04

Tprice88


3 Answers

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

number := -abs(number)
like image 141
Leo Avatar answered Oct 23 '22 21:10

Leo


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

if yourvariable > 0 then
    yourvariable := -yourvariable;
like image 21
RBA Avatar answered Oct 23 '22 23:10

RBA


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

like image 5
Axel A. García Avatar answered Oct 23 '22 22:10

Axel A. García