I'm using the abs() function in a probability calculation using float and int variables however I'm getting error messages. What I'm trying to do is get a decimal answer using abs() but it appears to only accept integer variables? How do I get the abs() to give me a a 3 decimal place answer.

Try the fabs() function for floating point numbers.

abs function is for doubles...fabs is for floats

abs function is for doubles...fabs is for floats

No. Care to try again?

Roll your own, it's just too simple ...

if (number < 0)  number = -number;

No. Care to try again?

its not? thats what my linux help manual said

don't supose you could explain that a little more, I got the feeling that fabs and abs do different things pther than double and floats?

Given the prototypes, I thought it was quite obvious. (You didn't follow the links and read the descriptions either, did you?)

  • abs is for int (not double)
  • fabs is for floating point (double or float)

Given the prototypes, I thought it was quite obvious. (You didn't follow the links and read the descriptions either, did you?)

  • abs is for int (not double)
  • fabs is for floating point (double or float)

i followed the links ..............never mind

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.