在 PHP 中使用数学是否有任何规则。当我尝试做一些简单的数学运算时,我得到了一些离谱的数字。
这是具体的脚本
$profit = $quote_1 - $entry;
这是完整脚本的片段
if ($productCount > 0) {
// get all the product details
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$symbol = $row["symbol"];
$sym = strtoupper($sym);
$entry = $row["entry"];
$exit = $row["exit"];
$openclosed = $row["openclosed"];
$entrydate = $row["entrydate"];
$profit = $quote_1 - $entry;
$color = "#000000";
$positive = "";
if ($profit >= 0){
$color = "#00a900";
$positive = "+";
}
else if ($profit < 0){
$color = "#ef3600";
$positive = "";}
if(empty($symbol)) {
echo nothing;
}
else {
$open = fopen("http://quote.yahoo.com/d/quotes.csv?s=$symbol&f=sl1d1t1c1ohgv&e=.csv", "r");
$quote = fread($open, 1000);
fclose($open);
$quote = str_replace("\"", "", $quote);
$quote = explode(",", $quote);
$quote_0 = ($quote[0]);
$quote_1 = ((float)$quote[1]);
$quote_2 = ($quote[2]);
$quote_3 = ($quote[3]);
$quote_4 = ((float)$quote[4]);
$quote_5 = ((float)$quote[5]);
$quote_6 = ((float)$quote[6]);
$quote_7 = ((float)$quote[7]);
$quote_8 = ((float)$quote[8]);
echo "<ul><li><div class='wrapPicks'>
<div class='symbolPicks'>
<div class='quoteTitle'>$quote_0</div>
</div>
<div class='bgPicks'>
<div class='quote'>Entry Price: $$entry</div>
<div class='quote'>Last trade: $$quote_1</div>
<!--<div class='quote'>Date: $quote_2</div>-->
<div class='quote'>Open P/L: <div class='bigGreen'><span style=\"color: $color\">$positive $$profit </span></div></div>
<!-- <div class='quote'>Change From Previous Close: $$quote_4</div>-->
<!--<div class='quote'>High: $$quote_6</div>
<div class='quote'>Low: $$quote_7</div>
<div class='quote'>Volume: $quote_8</div>-->
</div>
</div></li></ul>";
}
现在我想到的是,雅虎数据可能以字符串的形式出现,这可能会导致问题发生。我也不清楚我的 MYSQL 表是必须是 int 还是 VARChAR 可以接受?