у меня есть два поля
- сумма (десятичная (11, 2))
- gift_amount (десятичное число (11, 2))
Когда я выполняю обновление для значения, равного или ниже 999,99, оно сохраняется правильно.
Однако, если я перейду к этому, то значение будет уменьшено до 1 - 10.
Это известная проблема или я ошибаюсь, используя десятичную дробь?
Вот некоторый PHP-код того, что я делаю, чтобы сделать его более понятным (хотя я на 100% не виноват в PHP.
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;
}