我正在使用CodeIgniter的Active Record,我的代码是:
$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
作为输出。
答案 0 :(得分:2)
小心将货币存储为MySQL中的“DECIMAL”类型。如果您使用Float,您将得到不一致的结果。我知道你这里没有说过你使用的数据类型,但有些东西告诉我它可能不是DECIMAL(10,2)。