472,119 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

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 2441
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 leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.