March 7, 2019 at 11:10 pm
Hi,
DECLARE @p1 AS INT = 9, @p2 AS INT = 2;
SELECT CAST(@p1 AS NUMERIC(12, 2) / CAST(@p2 AS NUMERIC(12, 2));
Using the above I get '4.500000000000000'.
Surely it should be '0000000004.50'?
I am using SQL Server Management Studio v17.9.1 for this.
March 8, 2019 at 5:22 am
jonas.gunnarsson 52434 - Thursday, March 7, 2019 11:54 PMThe result is correct, use the str function, like:select str(cast(@p1 as numeric(12, 2)) / cast(@p2 as numeric(12, 2)), 12, 2);
No need to convert the number to a string, unnecessary overhead.
😎
Here is an example wrapping the calculation in a convert function.
DECLARE @p1 AS INT = 9, @p2 AS INT = 2;
SELECT
CONVERT(NUMERIC(12,2),CAST(@p1 AS NUMERIC(12, 2)) / CAST(@p2 AS NUMERIC(12, 2)),0);
March 8, 2019 at 5:55 am
USE Test
GO
DECLARE @p1 AS INT = 9, @p2 AS INT = 2;
SELECT CAST(@p1 AS NUMERIC(12, 2))/ CAST(@p2 AS NUMERIC(12, 2)) ReturnResult
INTO dbo.TestDivisionReturnType;
GO
EXEC sp_help 'dbo.TestDivisionReturnType'
GO
DROP TABLE dbo.TestDivisionReturnType
The return type of numeric(12,2) / numeric(12,2) is numeric(27,15)
March 8, 2019 at 4:17 pm
the result is correct. by convention whole numbers(integers) are not padded with leading zeros, decimals are however.
March 10, 2019 at 3:29 pm
Clocker - Friday, March 8, 2019 4:17 PMthe result is correct. by convention whole numbers(integers) are not padded with leading zeros, decimals are however.
Where on Earth did you come up with such a convention?
--Jeff Moden
Change is inevitable... Change for the better is not.
March 11, 2019 at 11:01 am
Jeff Moden - Sunday, March 10, 2019 3:29 PMClocker - Friday, March 8, 2019 4:17 PMthe result is correct. by convention whole numbers(integers) are not padded with leading zeros, decimals are however.Where on Earth did you come up with such a convention?
And show me even one product that will actually left-pad a number with leading 0's by default.
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
March 11, 2019 at 11:30 am
sgmunson - Monday, March 11, 2019 11:01 AMJeff Moden - Sunday, March 10, 2019 3:29 PMClocker - Friday, March 8, 2019 4:17 PMthe result is correct. by convention whole numbers(integers) are not padded with leading zeros, decimals are however.Where on Earth did you come up with such a convention?
And show me even one product that will actually left-pad a number with leading 0's by default.
My guess is BOL 😀
😎
This is just like dealing with managers, their importance is normally equivalent to the importance of leading and trailing zeros😉
March 11, 2019 at 1:13 pm
Eirikur Eiriksson - Monday, March 11, 2019 11:30 AMsgmunson - Monday, March 11, 2019 11:01 AMJeff Moden - Sunday, March 10, 2019 3:29 PMClocker - Friday, March 8, 2019 4:17 PMthe result is correct. by convention whole numbers(integers) are not padded with leading zeros, decimals are however.Where on Earth did you come up with such a convention?
And show me even one product that will actually left-pad a number with leading 0's by default.
My guess is BOL 😀
😎
This is just like dealing with managers, their importance is normally equivalent to the importance of leading and trailing zeros😉
Correct me if I'm wrong, Eirikur, but you make it sound like it states such a convention in BOL. To save some time, do you have link?
--Jeff Moden
Change is inevitable... Change for the better is not.
March 11, 2019 at 2:16 pm
Jeff Moden - Monday, March 11, 2019 1:13 PMEirikur Eiriksson - Monday, March 11, 2019 11:30 AMsgmunson - Monday, March 11, 2019 11:01 AMJeff Moden - Sunday, March 10, 2019 3:29 PMClocker - Friday, March 8, 2019 4:17 PMthe result is correct. by convention whole numbers(integers) are not padded with leading zeros, decimals are however.Where on Earth did you come up with such a convention?
And show me even one product that will actually left-pad a number with leading 0's by default.
My guess is BOL 😀
😎
This is just like dealing with managers, their importance is normally equivalent to the importance of leading and trailing zeros😉Correct me if I'm wrong, Eirikur, but you make it sound like it states such a convention in BOL. To save some time, do you have link?
Read BOL =
Bullshit On Line
😎
l
March 11, 2019 at 2:21 pm
Eirikur Eiriksson - Monday, March 11, 2019 2:16 PMJeff Moden - Monday, March 11, 2019 1:13 PMEirikur Eiriksson - Monday, March 11, 2019 11:30 AMsgmunson - Monday, March 11, 2019 11:01 AMJeff Moden - Sunday, March 10, 2019 3:29 PMClocker - Friday, March 8, 2019 4:17 PM!!!the result is correct. by convention whole numbers(integers) are not padded with leading zeros, decimals are however.Where on Earth did you come up with such a convention?
And show me even one product that will actually left-pad a number with leading 0's by default.
My guess is BOL 😀
😎
This is just like dealing with managers, their importance is normally equivalent to the importance of leading and trailing zeros😉Correct me if I'm wrong, Eirikur, but you make it sound like it states such a convention in BOL. To save some time, do you have link?
Read BOL =
Bullshit On Line
😎
l
OH!!! THAT BOL!!! 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
March 12, 2019 at 7:50 am
Thanks for the responses guys....
March 13, 2019 at 7:31 am
Jeff Moden - Monday, March 11, 2019 2:21 PMEirikur Eiriksson - Monday, March 11, 2019 2:16 PMJeff Moden - Monday, March 11, 2019 1:13 PMEirikur Eiriksson - Monday, March 11, 2019 11:30 AMsgmunson - Monday, March 11, 2019 11:01 AMJeff Moden - Sunday, March 10, 2019 3:29 PMJeff Moden - Monday, March 11, 2019 2:21 PMEirikur Eiriksson - Monday, March 11, 2019 2:16 PMJeff Moden - Monday, March 11, 2019 1:13 PMEirikur Eiriksson - Monday, March 11, 2019 11:30 AMsgmunson - Monday, March 11, 2019 11:01 AMJeff Moden - Sunday, March 10, 2019 3:29 PMClocker - Friday, March 8, 2019 4:17 PM!!!the result is correct. by convention whole numbers(integers) are not padded with leading zeros, decimals are however.Where on Earth did you come up with such a convention?
And show me even one product that will actually left-pad a number with leading 0's by default.
My guess is BOL 😀
😎
This is just like dealing with managers, their importance is normally equivalent to the importance of leading and trailing zeros😉Correct me if I'm wrong, Eirikur, but you make it sound like it states such a convention in BOL. To save some time, do you have link?
Read BOL =
Bullshit On Line
😎
lOH!!! THAT BOL!!! 😀
Where on Earth did you come up with such a convention?
And show me even one product that will actually left-pad a number with leading 0's by default.
My guess is BOL 😀
😎
This is just like dealing with managers, their importance is normally equivalent to the importance of leading and trailing zeros😉Correct me if I'm wrong, Eirikur, but you make it sound like it states such a convention in BOL. To save some time, do you have link?
Read BOL =
Bullshit On Line
😎
lOH!!! THAT BOL!!! 😀
+ a googolplex to the googolplex power, cubed !!!
Steve (aka sgmunson) 🙂 🙂 🙂
Rent Servers for Income (picks and shovels strategy)
March 13, 2019 at 8:22 am
sgmunson - Wednesday, March 13, 2019 7:31 AMJeff Moden - Monday, March 11, 2019 2:21 PMEirikur Eiriksson - Monday, March 11, 2019 2:16 PMJeff Moden - Monday, March 11, 2019 1:13 PMEirikur Eiriksson - Monday, March 11, 2019 11:30 AMsgmunson - Monday, March 11, 2019 11:01 AMJeff Moden - Sunday, March 10, 2019 3:29 PMJeff Moden - Monday, March 11, 2019 2:21 PMEirikur Eiriksson - Monday, March 11, 2019 2:16 PMJeff Moden - Monday, March 11, 2019 1:13 PMEirikur Eiriksson - Monday, March 11, 2019 11:30 AMsgmunson - Monday, March 11, 2019 11:01 AMJeff Moden - Sunday, March 10, 2019 3:29 PMClocker - Friday, March 8, 2019 4:17 PM!!!the result is correct. by convention whole numbers(integers) are not padded with leading zeros, decimals are however.Where on Earth did you come up with such a convention?
And show me even one product that will actually left-pad a number with leading 0's by default.
My guess is BOL 😀
😎
This is just like dealing with managers, their importance is normally equivalent to the importance of leading and trailing zeros😉Correct me if I'm wrong, Eirikur, but you make it sound like it states such a convention in BOL. To save some time, do you have link?
Read BOL =
Bullshit On Line
😎
lOH!!! THAT BOL!!! 😀
Where on Earth did you come up with such a convention?
And show me even one product that will actually left-pad a number with leading 0's by default.
My guess is BOL 😀
😎
This is just like dealing with managers, their importance is normally equivalent to the importance of leading and trailing zeros😉Correct me if I'm wrong, Eirikur, but you make it sound like it states such a convention in BOL. To save some time, do you have link?
Read BOL =
Bullshit On Line
😎
lOH!!! THAT BOL!!! 😀
+ a googolplex to the googolplex power, cubed !!!
Spot on Steve 😉
😎
March 15, 2019 at 3:06 pm
Eirikur Eiriksson - Monday, March 11, 2019 2:16 PMJeff Moden - Monday, March 11, 2019 1:13 PMEirikur Eiriksson - Monday, March 11, 2019 11:30 AMsgmunson - Monday, March 11, 2019 11:01 AMJeff Moden - Sunday, March 10, 2019 3:29 PMClocker - Friday, March 8, 2019 4:17 PMthe result is correct. by convention whole numbers(integers) are not padded with leading zeros, decimals are however.Where on Earth did you come up with such a convention?
And show me even one product that will actually left-pad a number with leading 0's by default.
My guess is BOL 😀
😎
This is just like dealing with managers, their importance is normally equivalent to the importance of leading and trailing zeros😉Correct me if I'm wrong, Eirikur, but you make it sound like it states such a convention in BOL. To save some time, do you have link?
Read BOL =
Bullshit On Line
😎
l
SOM (for those who don't remember: SOM = spewing on monitor ) 😛
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply