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 15 (of 15 total)
You must be logged in to reply to this topic. Login to reply