RE: Need unrounded precision

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

 



> -----Original Message-----
> From: Diogo Neves [mailto:dafneves@xxxxxxxxx]
> Sent: Monday, October 12, 2009 9:19 AM
> To: Andre Dubuc
> Cc: php-general@xxxxxxxxxxxxx
> Subject: Re:  Need unrounded precision
> 
> A simple way to do that would be:
> 
> $elapsed = strval( 28.56018 );
> $pos = strpos( $elapsed, '.' );
> echo $elapsed[ ++$pos ];
> 
> On Sat, Jan 2, 2010 at 2:20 AM, Andre Dubuc <aajdubuc@xxxxxxxxxxx>
> wrote:
> 
> > Hi,
> >
> > I need to extract the first digit after the decimal point from a
> number
> > such
> > as 28.56018, which should be '5'.


Couldn't this be done with just simple math functions?


$a = 28.56018;
$b = intval(($a*10)-(intval($a)*10));

or:

$a = 28.56018;
$b = intval(($a-intval($a))*10);


Jaime


-- 
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