Forum Moderators: coopster

Message Too Old, No Replies

Make a negative float positive

Simple function call?

         

trillianjedi

11:10 pm on Aug 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi guys,

Sorry - much searching, but I'm stuck for *what* to search for.

I have a negative float value, and if it's negative I need to turn it into a positive, eg:-

-2.36

.....and I need 2.36 as the result.

Is there a simple function for losing the sign, mathematically?

If not, would a simple:-

if (MyFloat < 0) {strip leading "-"};

cause any problems that you can foresee?

Thanks!

TJ

leadegroot

11:25 pm on Aug 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The PHP ABS function
[php.net...]
sounds like what you want

trillianjedi

11:55 pm on Aug 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Excellent - thanks. No wonder I couldn't find it...

TJ

Aleister

12:03 am on Aug 21, 2005 (gmt 0)

10+ Year Member



I like:

if ($MyFloat < 0) {$MyFloat *= -1;};