Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert float negative value to positive

Tags:

java

How to convert float negative value to float positive value

example -1.5 to 1.5

like image 618
Jones Avatar asked Jan 14 '11 09:01

Jones


People also ask

How do you change a negative float to positive?

To convert negative number to positive number (this is called absolute value), uses Math. abs(). This Math. abs() method is work like this “ number = (number < 0 ? -number : number); ".

How do you change a negative float to a positive in Python?

In Python, positive numbers can be changed to negative numbers with the help of the in-built method provided in the Python library called abs (). When abs () is used, it converts negative numbers to positive.

How do I change negative numbers to positive in Excel?

Convert negative numbers in place Add -1 to a cell and copy to the clipboard. Select the negative numbers you want to convert. Use Paste Special > Values + Multiply.

What if float is negative?

Float is often represented as a positive or negative number representing the number of days of delay. Essentially, negative float is the amount of time that must be saved to bring the project to completion on time.


3 Answers

Multiply it by -1.

Or negate it.

Or get the absolute value.

Basic arithmetics.

float neg = -1.5f;
float pos1 = neg * -1;
float pos2 = -neg;
float pos3 = Math.abs(neg);
like image 81
Oded Avatar answered Oct 04 '22 21:10

Oded


assign the negative:

float f = -1.5f;
f = -f;
like image 30
davin Avatar answered Oct 04 '22 21:10

davin


The Absolute Value Function in Java is Math.abs:

double f = Math.abs(-1.5); // f is now 1.5
like image 33
abelenky Avatar answered Oct 04 '22 21:10

abelenky