RE: [PHP] Need unrounded precision
| From: | Jaime Bozza | Date: | Mon, 12 Oct 2009 15:58:02 +0000 |
| Subject: | RE: [PHP] Need unrounded precision | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-298862@lists.php.net to get a copy of this message | ||
> -----Original Message-----
> From: Diogo Neves [mailto:dafneves@gmail.com]
> Sent: Monday, October 12, 2009 9:19 AM
> To: Andre Dubuc
> Cc: php-general@lists.php.net
> Subject: Re: [PHP] 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@webhart.net>
> 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