On Dec 7, 2007 9:51 AM, Nathan Rixham <[EMAIL PROTECTED]> wrote: > In-Built PHP Functions for parsing of basic arithmetic and if possible > fraction to decimal and decimal to fraction
PHP already handles half of what you're looking for by default. > $arithmetic_string = "3*5"; > echo arith($arithmetic_string); // returns float 15 <?=3 * 5;?> > $arithmetic_string = "1/2"; > echo arith($arithmetic_string); // returns float 0.5 <?=1 / 2;?> > $fraction_string = "1/4"; > echo fracdec($fraction_string); // returns float 0.25 <?=1 / 4; ?> > $dec_string = "0.5"; > echo decfrac($dec_string); // returns string "1/4" Now I see why you need PHP to do your math for you! ;-P There are functions written that do this now though. > I've used php for years, came accross the need for this today and was > suprised such a basic command wasn't there.. currently the only way I > can see to do it would be to eval.. which isn't the most secure method > for such a basic need. > > Regards > > Nathan > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Daniel P. Brown [Phone Numbers Go Here!] [They're Hidden From View!] If at first you don't succeed, stick to what you know best so that you can make enough money to pay someone else to do it for you. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php