我用笨的活動記錄和我的代碼是:爲什麼MySQL不能得到正確的數據?
$current_balance = $this->get_campaign_balance($click_report['campaign_id']);
$campaign_ledger = array(
'campaign_id' => $click_report['campaign_id'],
'description' => "Click Deduction from script",
'amount' => -1 * $click_report['advertiser_spend'],
'balance' => "" . $current_balance - $click_report['advertiser_spend'],
'meta_data' => $click_report['day'],
'timestamp' => time()
);
$this->db->insert('campaign_ledger', $campaign_ledger);
當我var_dump
的$campaign_ledger
我得到:
array(6) {
["campaign_id"]=>
string(3) "277"
["description"]=>
string(27) "Click Deduction from script"
["amount"]=>
float(-0.05)
["balance"]=>
float(89.95)
["meta_data"]=>
string(10) "2012-04-19"
["timestamp"]=>
int(1334881599)
}
但是,當數據進入我的數據庫中,balance
是91.36800000000001
爲一些原因。那麼,有什麼關係呢?
編輯
變爲DECIMAL(10,4)
後,我仍然得到91.3680
作爲輸出。
數據庫中的餘額字段的數據類型是什麼? – 2012-04-20 00:29:51
你期望得到什麼? – 2012-04-20 00:31:09
我把它作爲FLOAT,我改成了'DECIMAL(10,4)',但它仍然關閉 – Shamoon 2012-04-20 00:47:01