How to display/avoid the epsilon value in php [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Forcing output in standard mathematical notation in PHP
Output displayed: 2e+008
How to avoid displaying the epsilon value in php?
Output needed: 200000000
mysql table
amount float
if i enter 200000000 in input box it stores 2e+008 in mysql and just fetch the value through jquery using this code
$amount=$("[id=amountfee]").val();
<?php echo $amount ?>

You should look at the number_format() function: http://us2.php.net/manual/en/function.number-format.php

use DECIMAL or DOUBLE as data type instead of float. This will also help you to avoid problems you might have on float.

Related

how to store huge int value in php,I store 13262075231096090737 in mysql ,but it show as 1.3262075231096E+19 [duplicate]

This question already has answers here:
Turn off scientific notation MySQL
(2 answers)
Closed 3 years ago.
I use php to store a very big int in mysql ,the value is 13262075231096090737 ,but I echo that value,it shows as 1.3262075231096E+19, when I store as varchar,it also show as 1.3262075231096E+19. I want to know how to store a very huge int in mysql??
in your database change field type to 'text' instead of 'varchar'
The problem you are experiencing is not to do with the storage of the BIGINT, but rather the displaying of that number in PHP.
See this post for examples using:
number_format()
sprintf()
printf()
Why is PHP printing my number in scientific notation, when I specified it as .000021?

Limit echo string number [duplicate]

This question already has answers here:
Show a number to two decimal places
(25 answers)
Closed 5 years ago.
I'm currently working on retrieving data from coinmarketcap API and I would like to limit the strings to 5. I retrieve the data and then multiply the value *1.07 and the result to MXN, but the string is long, like 25.65675734343, I want to limit that string, this is my echo:
echo $xrpprice*$rate*$fxrates['rates']['MXN'];
Use round:
$result = $xrpprice*$rate*$fxrates['rates']['MXN'];
echo round($result,2);
In PHP you can use number_format to control how many decimal places. Assuming you don't want to limit the whole number to just five characters.
echo number_format($numberToFormat, $numberOfDecimalPlaces);
Please better explain your question. Also, what have you tried?

convert timestamp string to timestamp integer php [duplicate]

This question already has answers here:
Check whether the string is a unix timestamp
(13 answers)
Closed 6 years ago.
Here is my php code
var_dump($args['startdate']);
var_dump((int)$args['startdate']);die();
Here is output
string(13) "1468821556126" int(2147483647)
Expected output
string(13) "1468821556126" int(1468821556126)
Why this is happening and how to resolve this issue ?
You cannot get a reliable result because your number is too large to be represented as an integer.
echo PHP_INT_MAX; //2147483647 on my system
For a number as large as yours, if you need it in numerical format, cast it to a float instead of an integer
echo floatval('1468821556126'); //1.46882155613E+12
From there, if you're trying to get a date, I assume that this is Javascript time, which is in milliseconds. To convert to a Unix Timestamp, you'll then need to divide it by 1000.
It's happening because your $args['startdate'] is in miliseconds, you need to divide it by 1000
You're probably using a 32bit system. The number you're seeing is the maximum size of an int on a 32 bit machine.
Use float or change to a 64bit machine.
Ref: PHP Integer

PHP operator Procedence [duplicate]

This question already has answers here:
int((0.1+0.7)*10) = 7 in several languages. How to prevent this?
(7 answers)
Closed 9 years ago.
Can anybody figure out how the following statement evaluates to 7?
echo (int)( (0.1+0.7)*10 );
I was trying the operator precedence in PHP. So, if there is anybody who can help, it will be highly appreciated.
If you remove the (int) part, and run the follwing code instead:
echo number_format(((0.1+0.7)*10), 20);
The output will be 7.99999999999999911182. This value parsed to an integer will result to 7, as parsing a value to an integer will always floor the value.
Reading the following article should give you an idea of what's going on here.
In short, double values are always a binary value, and through that a 'product of 2^n', whichever will be the nearest to the decimal you said it should be. And with 2^n you dont have any chance to reach exactly 0.1.

Subtract two strings in PHP or mySQL to count differences [duplicate]

This question already has answers here:
Character-wise string diff in PHP
(4 answers)
Closed 9 years ago.
Is it possible to return the number of characters which differ between two strings?
In my case, I would like to run a check to quantify how much a user's draft has changed vs the database version. With this information, the system can decide weather or not the draft needs to be auto-saved.
For example:
echo string_diff("Hello world", "Hi World");
This should output "5", indicating that characters "ello" & "W" are different.
Is this possible with PHP? How about with mySQL?
On the PHP side your options are
similar_text which calculates the percent similarity between two strings
levenshtein - which calculates the edit distance between two strings (the number of key strokes it takes to transform string a into string b)
on mysql you can use this user defined function to calculate the levenshtein distance

Categories