Javascript - Identifying Positive 0 and negative 0 numbers

check if number is positive or negative javascript
math.sign javascript
zero in javascript
javascript negative number
javascript negative number to zero
write a javascript program to check from two given integers, if one is positive and one is negative
positive zero
how to compare negative numbers in javascript

I have a requirement where i have to identify if the number is a positive 0 or a negative 0 and do color coding for those numbers. This is applicable only for 0s and not greater or lesser than 0.


  1. 0.00000983 (Positive Zero)

  2. -0.0000343 (Negative Zero)

I tried below method but this does not help for values having decimals with 0. Please guide.

function isMinusZero(value) {
  return 1/value === -Infinity;

isMinusZero(0); // false
isMinusZero(-0); // true

Here is an alternative:

function isMinusZero(value) {
  if (, -0)) return true;   // handles OP's specific requirement
  if (value === 0) return false;
  return 1/Math.abs(Math.ceil(value)) === Infinity;

console.log(isMinusZero(1234)); // false
console.log(isMinusZero(-1223)); // false
console.log(isMinusZero(0)); // false
console.log(isMinusZero(-0)); // true
console.log(isMinusZero(0.0000000000000000000000000000000000000000976767)); // false
console.log(isMinusZero(-0.0000000000000000000000000000000000000000967676767)); // true
console.log(isMinusZero(-0.0000000000003400003400000000000000034000000000967676767)); // true

Is Negative Zero (-0) a Number in JavaScript?, returns either a positive or negative +/- 1, indicating the sign of a number passed into the argument. If the number passed into Math.sign() is 0� In the IEEE 754 standard used to represent the Number type in JavaScript, the sign is represented by a bit (a 1 indicates a negative number). As a result, there exists both a negative and a positive value for each representable number, including 0. This is why both -0 and +0 exist.

Math.sign(), Determining the sign of a number is super easy now with ES6's Math.sign! It will indicate whether the number is positive, negative or zero Math.sign: How to Check if a Number is Positive or Negative in JavaScript. Determining the sign of a � After this, inside the for loop, we will be giving a check to each Number and Check Whether it is Greater Than 0 or lesser than 0. As the Check is made, we will be Displaying Accordingly whether It is Positive Number Or Negative Number. You will be displaying the message Negative or Positive number along with the Indexing element in an array.

Another solution using

function isMinusZero(value) {
  return, value);

  isMinusZero(0), // false
  isMinusZero(-0) // true

Math.sign: How to Check if a Number is Positive or Negative in , There, one uses one bit for the sign (0 if positive, 1 if negative) and the remaining In JavaScript, all numbers are floating point numbers, encoded in double Hence, there are several ways to determine the sign of a zero. Java program to find Positive or Negative Number Write Java program to find Positive or Negative Number or zero using If Else Statement, Else If Statement, and Ternary Operator with example. If the number is greater than 0, then the given number is positive. If the number is less than 0, the given number is negative.

you can use Math.sign()

function isZeroSign(value){

return   Math.sign(value) > 0 ;



JavaScript's two zeros, JS Full Form � ReactJS | Class Based Components � How to detect HTTP or HTTPS then force redirect to HTTPS in JavaScript ? Return Value: The Math. sign() function returns five different values as It returns 0 if the argument passed is a positive zero. Example 2: When a negative number is passed as an argument:. To get a negative version of a number in JavaScript you can always use the ~ bitwise operator. For example, if you have a = 1000 and you need to convert it to a negative, you could do the following: a = ~a + 1;

Here is your solution

function isMinusZero(value) {
  return value.toString().startsWith("-");
  isMinusZero(0), // false
  isMinusZero(-0) // true

Javascript, Thusly, a lot of the "weirdness" in JS number systems is actually We must return true if the zero is negative and false if it is a positive zero. This article describes a UDF (custom function) that finds positive and negative numbers that net to approximately zero. The UDF lets you specify the range to use around 0 (zero). I created/modified an UDF to solve his question: Find positive and negative amounts that net to zero in excel. Array formula in cell range c23:V55:

Identifying Negative Zero - DEV, Angular � Complete Javascript Course 2020 � Cyber Security � Web Developer There is a value for negative zero, separate from regular (positive?) zero. The case of �0.0 � �0.0 is an error (specifically it's “not a number” or NaN). Therefore, to determine the sign of a zero value, you need to use the� Lex Program to Identify and Count Positive and Negative Numbers Lex program to take input from file and remove multiple spaces, lines and tabs Given some numbers, task is to identify the positive and negative numbers and print the count of negative and positive numbers.

Negative Zero, However, in most situations, JavaScript treats +0 and -0 as equivalent values. In JavaScript, division by zero of a non-zero finite number produces either and -0 preserves the equivalence 1 / (1 / x) == x when x is positive or negative infinity. I'm looking for a formula that can knock off positive and negative that net to zero. I'm currently using Microsoft Excel 2016 For Eg : Cell A1 contains number 2 Cell A2 contains number 2 Cell A3 contains number -4 Here in the adjoining cells i.e B1, B2, B3 i need resulting values as TRUE since they are knocking off

Testing for -0 in JavaScript, This article explores numbers in JavaScript, including some common, and This results in two zeroes – a positive zero, +0, and a negative zero, -0. Therefore, to determine if a number is equal to -0, we must check that it is� In the below program, to find whether A is positive, negative or zero; first the number is taken as input from the user using scanf in , and then A is checked for positive using statement and , and operators. Below is the C program to find whether a number is positive, negative or zero.

  • And, what wrong with your solution?
  • does not work for 0.0000098 or any such number
  • but 0.00000983 is not any zero, I don't understand the requirement as you've stated it ... clearly that number is not zero
  • Bravo - requirement was anything greater than 0 but less than 1 i had to show positive green. anything less than 0 but greater than -1 i need to show as -0.
  • Besides technically your output is not zero at all, because it doesn't follow multiplicative property of zero : (+1)*0 ≠ (-1)*0 in your case.
  • It would be nice to demonstrate the OP with an example in the posted function.
  • Cool, but cannot be used to test 0.0000000009 === 0 :)
  • isMinusZero(-0) returns false, because (-0).toString() is just "0"
  • I made you a snippet. It returns false,false