The number is 13911392101301011 , and regardless of using sprintf or number_format , I get the same strange result.
13911392101301011
sprintf
number_format
sprintf('%017.0f', "13911392101301011"); // Result is 13911392101301012 number_format(13911392101301011, 0, '', ''); // Result is 13911392101301012 sprintf('%017.0f', "13911392101301013"); // Result is 13911392101301012 number_format(13911392101301013, 0, '', ''); // Result is 13911392101301012
This is a job. > !!
$num1 = "13911392101301011"; $r = mysql_query("Select @sum:=$num1"); $sumR = mysql_fetch_row($r); echo $sum = $sumR[0];
You can do it as follows: -
ini_set("precision",25); // change 25 to whatever number you want or need $num = 13911392101301011; print $num;
Since you are dealing with large numbers here, you can save them as strings and perform a numerical operation on string values ββusing BCMath functions .
$val = "13911392101301011"; echo $val; // 13911392101301011 echo bcadd($val, '4'); // 13911392101301015 echo bcmul($val, '2'); // 27822784202602022
Since you actually have a number as a string, use the %s modifier:
%s
sprintf('%s', "13911392101301011"); // 13911392101301011
Note that PHP uses a signed integer. The size depends on your system.
32-bit system:
2^(32-1) = 2147483648
64-bit system:
2^(64-1) = 9223372036854775808
-1 because 1 bit is reserved for the sign flag.
-1
The documentation states that $ number in number_format is a float , so there is an explicit type. The equivalent will look like this:
sprintf('%017.0f', (float) "13911392101301011");
The float is accurate to 14 digits and your number has 17 digits.
Your call to number_format sets the value. and to space
string number_format ( float $number , int $decimals = 0 , string $dec_point = '.' , string $thousands_sep = ',' )
try the following:
number_format(13911392101301011, 0, '.', ',');
Source: https://habr.com/ru/post/1479862/More articles:How to use the same named class in PHP without namespace? - phpAsp.Net WebAPI and AttributeRouting - no overloaded attribute constructor? - asp.net-web-apiFlicker and "CreateParams" - .netPDO with MySQL does not work when activating email - phpTheir way to stop the image from flickering when resizing? - c #Why doesn't my OData answer have navigation features - odataRegular expression - checking for an integer doesn't work - javascriptWhy is changing a numeric value using number_format ()? - phpThe Facebook application works only for the administrator. What for? - asp.netPHP preg_split ignores escape sequence - splitAll Articles