Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* SQL Division
- A coworker and I were trying to run some statistics this week and found something we thought
- interesting. Some of you may already know this, but we didn't.
- When performing division, if both divisor and dividend are whole numbers, the result will be
- a whole number, even if the answer would be a decimal. However, if either the divisor or
- dividend are a decimal, the result will also be a decimal.
- */
- print 15/10
- print 15/10.0
- print 15*.1
- print 15*.10
- /* Results
- 1
- 1.500000
- 1.5
- 1.50
- */
- /*
- This behavior was particularly confusing when we tried to cast the initial problem as
- a decimal, but it still left off the fractional portion. This was because the answer
- was determined before it did the cast.
- */
- print cast(15/10 as decimal(10,2))
- print cast(15/10.0 as decimal(10,2))
- print cast(15*.1 as decimal(10,2))
- print cast(15*.10 as decimal(10,2))
- /* Results
- 1.00
- 1.50
- 1.50
- 1.50
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement