Re: Need unrounded precision

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Kim Madsen wrote:
Hello

Andre Dubuc wrote on 2010-01-02 02:20:
Hi,

I need to extract the first digit after the decimal point from a number such as 28.56018, which should be '5'.

Since no one came up with the simple solution:

$num = "28.56018";
ereg("^[0-9]+\.([0-9]){1}", trim($num), $regs);
if($regs[1])
  $digit = $regs[1];
else
  print "no digit found";

My submission for a "simple" solution. I wish I had xslt2 =(
<xsl:template name="firstDigit">
   <xsl:param name="number"/>
<xsl:value-of select="number(substring(substring-after(number(translate(normalize-space($number),translate(normalize-space($number),'.0123456789',''),'')),'.'),1,1))"/>
</xsl:template>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux