?
Solved

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

Posted on 2011-09-10
3
Medium Priority
?
317 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 400 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
Suggested Courses

770 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