Mysql issue with decimal
Posted
by azz0r
on Stack Overflow
See other posts from Stack Overflow
or by azz0r
Published on 2010-03-25T17:53:30Z
Indexed on
2010/03/25
19:23 UTC
Read the original article
Hit count: 381
Hello, I have two fields - amount (decimal (11, 2)) - gift_amount (decimal (11, 2))
When I do an update on either for a value equal to or below 999.99, it saves correctly.
However, if I go over that, then it drops the value right back to down 1 - 10.
Is this a known issue or am I going wrong using decimal?
Heres some PHP code of what I'm doing just to make it clearer (although I'm 100% its not the PHP's fault.
if ($total_balance >= $cost) {
if ($this->user->balance->gift_amount > 0) {
$total_to_be_paid = number_format($cost, 2) - number_format($this->user->balance->gift_amount, 2);//figure out how much is left after the gift total
$this->user->balance->gift_amount -= number_format($cost, 2); //deduct from the gift balance
$this->user->balance->gift_amount = (number_format($this->user->balance->gift_amount, 2) < 0) ? number_format(00.00, 2) : number_format($this->user->balance->gift_amount, 2); //if the gift balance went below 0, lets set it to 0
if ($total_to_be_paid > 0) {
$this->user->balance->amount = number_format($this->user->balance->amount, 2) - number_format($total_to_be_paid, 2);
}
} else {
$this->user->balance->amount = number_format($this->user->balance->amount, 2) - number_format($cost, 2);
}
if ($object = Model_ClipBought::create(array('clip_id' => $clip->id, 'user_id' => $this->user->id, 'currency_name' => $user_currency, 'cost' => $cost, 'downloads' => $clip->downloads, 'expires' => time() + ($clip->expires * 86400)))) {
$this->user->balance->save();
$download = new Model_Download(ROOT_PATH."/public/files/Clip/$clip->file_url");
$download->execute();
} else {
throw new exception('We could not finish the purchase, this has been reported, sorry for the inconvenience.');
}
} else {
throw new exception('You dont have enough money in your account todo this');
}
exit;
}
© Stack Overflow or respective owner