By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,934 Members | 1,538 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

ROUND function

code green
Expert 100+
P: 1,726
I wish to ROUND a calculation to one decimal place without any trailing zeroes.
I thought this would be simple. I am using
Expand|Select|Wrap|Line Numbers
  1. CASE WHEN retail > 0 
  2. THEN ROUND((retail - wholesale)/retail,1)
  3. ELSE 0 END profit,
But I am getting results like 0.20000000000000001
and 0.29999999999999999.
Can anybody explain why and how to return only 0.20 and 0.29
Feb 22 '08 #1
Share this Question
Share on Google+
2 Replies


ck9663
Expert 2.5K+
P: 2,878
I wish to ROUND a calculation to one decimal place without any trailing zeroes.
I thought this would be simple. I am using
Expand|Select|Wrap|Line Numbers
  1. CASE WHEN retail > 0 
  2. THEN ROUND((retail - wholesale)/retail,1)
  3. ELSE 0 END profit,
But I am getting results like 0.20000000000000001
and 0.29999999999999999.
Can anybody explain why and how to return only 0.20 and 0.29
Try putting the CASE inside the ROUND. Something like

round(
CASE WHEN retail > 0
THEN (retail - wholesale)/retail
ELSE 0 END
,1) profit

-- CK
Feb 22 '08 #2

code green
Expert 100+
P: 1,726
I have used CAST
Expand|Select|Wrap|Line Numbers
  1. CASE WHEN retail > 0 
  2. THEN CAST(ROUND((retail - wholesale)/retail,1) AS DECIMAL(5,1))
  3. ELSE 0 END profit,
Feb 25 '08 #3

Post your reply

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