How to convert a positive number to negative in JavaScript

Last updated on Dec 15, 2022 by Suraj Sharma



In this tutorial, you will learn how you can convert a positive number to a negative number in javaScript


To convert a positive number to a negative number in JavaScript, we use the minus sign (-).


let x = 25;
x = -x;


We can convert a string to a number with a negative sign using the parseInt() or parseFloat() function and then use the negation operator to change its sign.


let str = "5";
let x = -parseInt(str); // -5

let y = -parseFloat('2.23'); // -2.23


Related Solutions


Rate this post


Suraj Sharma is the founder of Future Gen AI Services. He holds a B.Tech degree in Computer Science & Engineering from NIT Rourkela.