Reply to Re: Function to convert to positive number?

Your name:

Reply:


Posted by Bonge Boo! on 09/26/67 11:41

On 3/3/06 16:20, in article 51_Nf.29511$wl.1331@text.news.blueyonder.co.uk,
"d" <d@example.com> wrote:

>> This is driving me slightly nuts. I want to do some very simple
>> arithmetic,
>> but always make sure I return a positive number, even if the result of the
>> calculation is a negative.
>>
>> Basically convert -4 to 4, etc.
>>
>> So I've been trawling the manual for functions and Googling, and can't
>> find
>> a thing. Lots of stuff about formatting string with sprintf, and stuff
>> about
>> converting float to ints, but nothing as obvious as this.
>>
>> Suggestions gratefully received.
>
> Even if the abs() function didn't exist, which it does, this is a very
> simple problem to solve:

One day I will understand the naming convention of function in the manual. I
spnd hours lookingfor the wrong soet ofthing..

> function new_abs($s) {
> if ($s<0) $s*=-1;
> return $s;
> }

Obvious. Multiply -ve with -ve to get +ve. God my maths is rusty

And thanks.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация