May be this will work
$elapsed = 28.56018;
$elapsed_rel = (int) 28.56018;
$elapsed_deci = $elapsed - $elapsed_rel;
$deci = ((int) ($elapsed_deci * 10))/10;
$final = $elapsed_rel + $deci;

With regards,

Chetan Dattaram Rane | Software Engineer | Persistent SystemsĀ  | Cell: +91 9766646714 | Tel: +91 (0832) 30 79228
Innovation in software product design, development and delivery-

-----Original Message-----
From: Arno Kuhl []
Sent: Monday, October 12, 2009 12:07 PM
To: 'Andre Dubuc';
Subject: RE: [PHP] Need unrounded precision

-----Original Message-----
From: Andre Dubuc []
Sent: 02 January 2010 03:20 AM
Subject: [PHP] Need unrounded precision


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:


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



One way that should work regardless the number of digits before/after the
decimal is:
- convert to string (sprintf or typecast)
- strpos the decimal
- grab the char from the next position


PHP General Mailing List (
To unsubscribe, visit:

This e-mail may contain privileged and confidential information which is the 
property of Persistent Systems Ltd. It is intended only for the use of the 
individual or entity to which it is addressed. If you are not the intended 
recipient, you are not authorized to read, retain, copy, print, distribute or 
use this message. If you have received this communication in error, please 
notify the sender and delete all copies of this message. Persistent Systems 
Ltd. does not accept any liability for virus infected mails.

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to