number_format()无法转换科学记数法
I have some float values being looped through an array that are outputting in scientific notation.
I need to convert the scientific notation to a regular flat float long notation value.
I tried number_format(), but it still outputs in scientific notation until the very last cycle of my loop?
<?php
$parray = array(array('BTC-EXP','1',0.000097,1),array('BTC-VOX',7,number_format(0.000075,8),7));
for ($x = 0; $x <= 1; $x++) {
var_dump($parray);
foreach($parray as $pairp){
echo "
Debug info! Limit
";
echo $pairp[2];
echo "
";
print_r(number_format($pairp[2],8));
}
}
?>
output:
Debug info! midpoint
array(2) {
[0]=>
array(4) {
[0]=>
string(7) "BTC-EXP"
[1]=>
string(1) "1"
[2]=>
float(9.7E-5)
[3]=>
int(1)
}
[1]=>
array(4) {
[0]=>
string(7) "BTC-VOX"
[1]=>
int(7)
[2]=>
string(10) "0.00007500"
[3]=>
int(7)
}
}
Debug info! Limit
9.7E-5
0.00009700
Debug info! Limit
0.00007500
0.00007500
Debug info! midpoint
array(2) {
[0]=>
array(4) {
[0]=>
string(7) "BTC-EXP"
[1]=>
string(1) "1"
[2]=>
float(9.7E-5)
[3]=>
int(1)
}
[1]=>
array(4) {
[0]=>
string(7) "BTC-VOX"
[1]=>
int(7)
[2]=>
string(10) "0.00007500"
[3]=>
int(7)
}
}
Debug info! Limit
9.7E-5
0.00009700
Debug info! Limit
0.00007500
0.00007500
How do I convert my float values to long notation through an entire cycle (deny short notation)?
In your $parray, you are storing one number as a float (0.000097) and in the other you're storing the result of number_format(0.000075,8), which is a string.
It's not surprising then, that when you call
echo $pairp[2];
on 0.000097, that you see 9.7E-5, but when you echo it for number_format(0.000075,8) you see a string representation (0.00007500).
Let's do the same for print_r(number_format($pairp[2],8));
. When it's called for float (0.000097), it formats it as a string and you see 0.00009700. When it's called for "0.00007500", this string is converted to a float 0.000075, which is then converted back to a string "0.00007500".