SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mysql issue with decimal

    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.

    Code MySQL:
    	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;
    	}

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    There is no SQL query/code in what you pasted

    You should first verify that PHP is producing the query (with the amount) you want before you start debugging MySQL


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •