# Thread: convert negative to positive value

1. ## convert negative to positive value

Ok, my math skills are a little rusty. I'm generating two random negative numbers
<font class="small">Code:</font><hr /><pre>
nDateDecrement := RndUniN(-88..-28);
nDateDecrement2:= RndUniN(-78..-10);
While nDateDecrement2 &lt; (nDateDecrement+7) do
nDateDecrement2:= RndUniN(-78..-10);
End;
</pre><hr />
When all is said and done I want to know the range in weeks of the values I've generated.
<font class="small">Code:</font><hr /><pre>
Print("Date differential is "+ string((nDateDecrement-nDateDecrement2)/7)+" weeks",NULL,Text_Blue);
</pre><hr />
But of course my output is a negative number that comes back in the print statement like this:
Date differential is -7 weeks
I'd like to take this value and store it in a DB as a positive value, but as I said, my math skills this afternoon seem to have deserted me.
Oh yeah, I forgot to mention that I pass these numbers through a function that always changes the numbers so that they both fall on a Friday so they're always at least 7 days apart and the result is always a whole number.
Thanks

2. ## Re: convert negative to positive value

Never mind, I got it as soon as I posted this....D'Oh!
<font class="small">Code:</font><hr /><pre>
Print("Date differential is "+ string(0-((nDateDecrement-nDateDecrement2)/7))+" weeks",NULL,Text_Blue);
</pre><hr />
[img]/images/graemlins/smile.gif[/img]

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.