Multiply Column by 1.0003 and then round result up to nearest whole number.
Code:
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.
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.
Code:
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.
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;
Bookmarks