Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:33840 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54536 invoked by uid 1010); 7 Dec 2007 17:37:20 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 54521 invoked from network); 7 Dec 2007 17:37:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Dec 2007 17:37:20 -0000 Authentication-Results: pb1.pair.com header.from=ipso@snappymail.ca; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ipso@snappymail.ca; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain snappymail.ca designates 216.139.220.195 as permitted sender) X-PHP-List-Original-Sender: ipso@snappymail.ca X-Host-Fingerprint: 216.139.220.195 216-139-220-195.aus.us.siteprotect.com Linux 2.6 Received: from [216.139.220.195] ([216.139.220.195:60395] helo=mail.timetrex.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 29/51-45053-EC489574 for ; Fri, 07 Dec 2007 12:37:19 -0500 Received: from [192.168.1.9] (S0106005004c32d38.ok.shawcable.net [24.71.236.35]) by mail.timetrex.com (Postfix) with ESMTP id 2B9DA4C001; Fri, 7 Dec 2007 09:37:15 -0800 (PST) To: nrixham@gmail.com Cc: internals@lists.php.net In-Reply-To: <01.E6.00959.D3E59574@pb1.pair.com> References: <01.E6.00959.D3E59574@pb1.pair.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-KGuIDM130hBAtPaIsWhD" Date: Fri, 07 Dec 2007 17:37:13 +0000 Message-ID: <1197049033.26965.141.camel@ipso.snappymail.ca> Mime-Version: 1.0 X-Mailer: Evolution 2.21.2-1mdv2008.1 Subject: Re: [PHP-DEV] Thoughts on Feature Request - Arithmetic From: ipso@snappymail.ca (Mike) --=-KGuIDM130hBAtPaIsWhD Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Yes, an easy way to handle this functionality that is safe to use with user input would be REALLY nice.=20 Specifically for allowing users to specify custom formulas to do all sorts of nifty stuff. Especially in reporting and payroll/commission applications.=20 We're currently working on a reporting class where we would like the user to able to specify custom columns in XML, ie: $col5 =3D ($col1 / $col2) * ($col3 / $col4) Or in our payroll application where customers want to calculate custom commissions for sales people: $commission =3D ($gross_sales - $gross_pay - $medical_benefits - $chargebacks) * $employee_commission_bracket On Fri, 2007-12-07 at 14:51 +0000, Nathan Rixham wrote: > In-Built PHP Functions for parsing of basic arithmetic and if possible=20 > fraction to decimal and decimal to fraction >=20 > $arithmetic_string =3D "3*5"; > echo arith($arithmetic_string); // returns float 15 >=20 > $arithmetic_string =3D "1/2"; > echo arith($arithmetic_string); // returns float 0.5 >=20 > $fraction_string =3D "1/4"; > echo fracdec($fraction_string); // returns float 0.25 >=20 > $dec_string =3D "0.5"; > echo decfrac($dec_string); // returns string "1/4" >=20 > I've used php for years, came accross the need for this today and was=20 > suprised such a basic command wasn't there.. currently the only way I=20 > can see to do it would be to eval.. which isn't the most secure method=20 > for such a basic need. >=20 > Regards >=20 > Nathan >=20 --=20 Mike --=-KGuIDM130hBAtPaIsWhD Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBHWYTJMhKjsejwBhgRAiPjAKCIwb2g7pDAlXiaWNIJqJG4TcjLbACfRlQc 2vsbnDXyKbmhWb9d+7nvGmw= =4mcX -----END PGP SIGNATURE----- --=-KGuIDM130hBAtPaIsWhD--