Jump to content

Recommended Posts


<?php

$a = 350000;
$b = 3600000000;

echo $hmm = $a / $b;

 

outputs

 

9.7222222221617E-5

 

while

 


<?php

$a = 350000;
$b = 360000000;

echo $hmm = $a / $b;

 

outputs

 

0.000972222222

 

its only one digit shorter,

 

how can I get the first code to produce the same results, Ive tried using float, int maxes out and Ive changed my floating point in php.ini, no luck

Link to comment
https://forums.phpfreaks.com/topic/237179-integer-to-big-php-math-calculations/
Share on other sites

ok that works but it shortens up the decimal and rounds it, is there a way to have it calculate the decimal without rounding it?

 

like 0.00092144444443

 

rounds to 0.000920

 

how can I get it to keep it at 0.00092144444443

 

bcsub($a,$b);

ok that works but it shortens up the decimal and rounds it, is there a way to have it calculate the decimal without rounding it?

 

like 0.00092144444443

 

rounds to 0.000920

 

how can I get it to keep it at 0.00092144444443

 

 

The correct result of 350000 / 360000000 = 0.0009722222222.. not 0.0009214444.. The reason to why you get an incorrect output is due to the precision loss of a float. Using the BCMath module of PHP you get:

 

echo bcdiv(350000, 360000000, 10); // 0.0009722222

 

10 is the level of precision you need.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.