Solved

how do I check the sign of a java script variable ?

Posted on 2011-09-10
3
316 Views
Last Modified: 2012-05-12
how do I check the sign of a java script variable ?

Here is my input/output to illustrate the problem.

Example Input/output:
Input:  var temp="-2"
Output:  This is a negative number . absolute value is =2

Input:  var temp="2"
Output:  This is a positive number . absolute value is 2

Input:  var temp="0"
Output:  This is a zero . absolute value is 0

I'm worried as javascript variable are unsigned . How do I check for a negative number then like above ?
0
Comment
Question by:cofactor
[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
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Expert Comment

by:ansudhindra
ID: 36516238
check if it less than 0, then multiply by -1
then you will get absolute..
0
 
LVL 13

Accepted Solution

by:
ansudhindra earned 100 total points
ID: 36516239
or you can do it like
var t=parseInt("-7");
if(t<0) { t=t*-1; }

alert("absolute value is "+t);
0
 
LVL 82

Expert Comment

by:leakim971
ID: 36516475
var temp="-2"
var tempIsNegative = !(temp == Math.abs(temp)); // true or false
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

728 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