How do I convert a positive number to negative?

ぃ、小莉子 提交于 2019-12-04 02:36:35

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

Tenzin

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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!