Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

How to check if number is positive or negative

Posted on 2006-11-18
Medium Priority
6,558 Views
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
Question by:dpinto04
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 25

Expert Comment

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

CWS (haripriya) earned 80 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

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll