Solved

How to check if number is positive or negative

Posted on 2006-11-18
6
6,493 Views
Last Modified: 2012-05-05
In classic asp, how do I check if a number is positive or negative.
Say 20 - 10 = -10. How do i check if its - 10?
I'm tryin to do a sales report graph where todays data is compared with yesterdays and the percent of increase or decrese is displayed.
So if its -10 Response.write "Decrease in Sales"
0
Comment
Question by:dpinto04
6 Comments
 
LVL 25

Expert Comment

by:kevp75
ID: 17973893
you can format a number....

<%=formatnumber(strNumber,2,0,-1)%>

this will put a parentheses around a negative number....so I guess, you could always do a string check against it...

if instr(formatnumber(strNumber,2,0,-1),"(") > 0 then
  response.write("Decrease In Sales"
end if
0
 
LVL 16

Accepted Solution

by:
CWS (haripriya) earned 20 total points
ID: 17977497
Dim numA, numB, numDiff

numDiff = numA - numB

' All negative numbers are less than zero.
if numDiff < 0 then
      Response.write "Decrease in Sales"
end if

0
 
LVL 9

Expert Comment

by:deathtospam
ID: 17979465
The VBScript Sgn function ( http://tinyurl.com/yz9rpo ) sounds like what you need:

====================================
Arguments
The number argument can be any valid numeric expression.

Return Value
The Sgn function has the following return values:

If number is  Sgn returns  
Greater than zero
 1
Equal to zero
 0
Less than zero
 -1
====================================


-= DeathToSpam =-
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now