469,072 Members | 1,849 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,072 developers. It's quick & easy.

Increasing by percentage

1
hi

im trying to update one of the records in my table 'City' called 'Population' by 5%.

UPDATE City
SET
Population= Population * 1.05;

The calculation seems correct but its just the final result which seems to not have proper rounding.

for example
one of the records in 'Population' is 1.659.000
after i use the update function my final answer comes out to 1.74195 rather than 1.741.950
Mar 16 '11 #1
1 2404
code green
1,726 Expert 1GB
This is because of the way computers handle floating point numbers.
This is a full lecture on any computer science module and is worth a little research if interested.

Suffice to say do not trust the return values from any calculation or comparison involving floating point numbers.

ROUND seems an obvious solution but this does not work on my system.
I use CAST(.............. AS DECIMAL(10,4))
which returns numbers to 4 decimal places.
Mar 16 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Conax | last post: by
22 posts views Thread by Les Juby | last post: by
15 posts views Thread by Joe Lester | last post: by
5 posts views Thread by James Conrad StJohn Foreman | last post: by
6 posts views Thread by Hacking Bear | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.