SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Error in Calculating Floor() value in SQL


Error in Calculating Floor() value in SQL

Author
Message
yensin 20332
yensin 20332
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 Visits: 18
Hi all,

I need to calculate numbers of money notes needed for salary preparation.
I have problem with the last column, i.e. USD1. The value return is 3 instead of 2.
SELECT FLOOR(2.78) ==> return 2.

I am not sure why my following code return 3.

DECLARE @GrossPay Decimal(12,2)
SET @GrossPay = 132.78
SELECT @GrossPay,
FLOOR(@GrossPay/100) AS USD100,
FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50) AS USD50,
FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50)/20) AS USD20,
FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50 - (FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50)/20))*20)/10) AS USD10,
FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50 - (FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50)/20))*20 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50 - (FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50)/20))*20)/10))*10)/5) AS USD5,
FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50 - (FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50)/20))*20 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50 - (FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50)/20))*20)/10))*10-(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50 - (FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50)/20))*20 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50 - (FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100 -(FLOOR((@GrossPay - FLOOR(@GrossPay/100)*100)/50))*50)/20))*20)/10))*10)/5))*5)/1) AS USD1


Hope that anyone can help me with this.

Thanks in advance!
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search