Results 1 to 3 of 3

Thread: Multiply Column by 1.0003 and then round result up to nearest whole number.

  1. #1
    Join Date
    Jun 2006
    Under your bed

    Multiply Column by 1.0003 and then round result up to nearest whole number.

    UPDATE `accounts` SET `bank_balance` = `bank_balance` + ceiling(`bank_balance` * 1.0003) WHERE `user_id` = 1
    This is supposed to multiply the bank balance by 1.0003 and then always round the result up to the nearest whole number So, for instance, if you had 5,000 points in your account, this would multiply it by 1.0003 which would give you 5,001.5 Then the round() function should round this up to 5,002

    However, what's happening is MySQL is just doubling the bank balance and adding 1 to it. So a balance of 5,000 turns into 10,001, for example.

    How can I get it to round it like I want?
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  2. #2
    Join Date
    Oct 2010
    I'm unable to get the same results as you. In fact this simplified queries returns 5002 as expected:

    SELECT CEILING( 5000 * 1.0003 )
    And building a dummy table and running your query against it also produces the results you say you expect.

    CREATE TABLE EvenStar (
       id int not null auto_increment primary key,
       balance int not null
    insert into EvenStar (balance) values (1000),(2000),(5000),(7000);
    update EvenStar SET balance = balance + CEILING(balance * 1.0003);
    SELECT * FROM EvenStar;
    The only thing I can think is there is some other piece of information I'm not properly recreating.
    www.rdennispallas.com <-- Personal Site, changing regularly cuz its ugly.

  3. #3
    Join Date
    Jul 2010
    try converting balance to a float or double first.... perhaps you're coercing 1.0003 to become an integer somehow (in which case it will probably just be 1 and do nothing).
    I use (, ; : -) as I please- instead of learning the English language specification: I decided to learn Scheme and Java;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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