Re: Need unrounded precision

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

 



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'.
>
> I've tried a few methods to accomplish this. If I use 'ini_set' I would
> need
> to know the number of digits before the decimal (which, unfortunately, I
> would not have access to).
>
> Then I've tried:
>
> <?php
>
>        $elapsed = 28.56018;
>
>        $digit = round($elapsed, 1); // rounds result is '6'
>        $digit = number_format($elapsed, 1); // still rounds result to '6'
>
> ?>
>
> What I need is only the first digit after the decimal -- all the rest could
> be 'chopped' or discarded but without rounding the first digit after the
> decimal point.
>
> Is there any way of doing this?
>
> I'm stumped.
>
> Tia,
> Andre
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


-- 
Thanks,

Diogo Neves
Web Developer @ SAPO.pt by PrimeIT.pt

[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