RobertPuerco RobertPuerco - 1 year ago 166
PHP Question

Float to bigint

Ok, so I have this float number :-

$floatval = '1.05143617E+18';

It's equivalent integer is :-


Using php, I'm trying to convert this float number to the required integer value.

Here is my try :-

$floatval = '1.05143617E+18';

function convert($floatval)
$divided = explode('+', $floatval);
$first = floatval($divided[0]);
$second = intval($divided[1]);
$final = intval($first * pow(10, $second));
return $final;

Output :-


Whatever I try, the output is not coming as required. Where am I doing mistake?

Answer Source
$floatval = (float) '1.05143617E+18';
$intval = (int) $floatval;

Output: int(1051436170000000000)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download