Re: Fractions

From: Date: Sun, 24 May 2009 23:57:22 +0000
Subject: Re: Fractions
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-293093@lists.php.net to get a copy of this message
Mark Kelly wrote:
Hi. On Sunday 24 May 2009, Ron Piggott wrote:
Is there a way to remove the trailing '0'?
$width = number_format($width,2);
Also is there a way to have the original fraction display (1/4), as well as have provision for 1/8 and 3/8 and 1/2, etc. display?
On this one I suspect you'd have to write your own function, but maybe someone else knows better.
yup you need to write your own functions - there was a request to internals a year or two ago, and it was decided that fractions were so easy to implement in userland and so rare that people should just implement them with there own code. not expressly hard echo '1/' . (1/0.25); should be 1/4 i do believe or in this scenario $val = (float)'6.250'; $fract = $val - floor($val); echo '1/' . (1/$fract); the above code really won't do for 3/8's or suchlike though just a quick pointer - from here on your in userland :p

« previous php.general (#293093) next »