I am having the negative floating point number as:
a = -0.340515;
to convert this into positive number I used the abs() method as:
a = abs(a);
the result is a = 0.000000;
But I need the result as 0.340515
.
Can anyone tell me how to do this.
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.
abs()
is for integers only. For floating point, use fabs()
(or one of the fabs()
line with the correct precision for whatever a actually is)
You have to use:
abs() for int
fabs() for double
fabsf() for float
Above function will also work but you can also try something like this.
if(a<0) { a=-a; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With