how to reverse a number js code example

Example 1: reverse number javascript

// Function to reverse Number
function reverseNum(n) {
  let r = n.toString().split('').reverse().join('');
  return Math.sign(n) * parseInt(r);
}

// Call
reverseNum(-267);
reverseNum(31522);

// Outputs
-762
22513

Example 2: reverse int js

function reverseInt(n) {
  let reversed = n.toString().split("").reverse().join("");
  //from string to integer
  reversed = parseInt(reversed);

  if (n < 0) {
    return reversed * -1;
  }

  return reversed;
}

Example 3: how to flip a Number in javascript

function reverse_a_number(n)
{
	n = n + "";
	return n.split("").reverse().join("");
}
console.log(reverse_a_number(32243));

Example 4: reverse number in js

function reversedNum(num) {
  return (
    parseFloat(
      num
        .toString()
        .split('')
        .reverse()
        .join('')
    ) * Math.sign(num)
  )                 
}

Example 5: js reverse number

const reversedNum = num => parseFloat(num.toString().split('').reverse().join('')) * Math.sign(num)