November 22, 2021 at 2:11 pm
HI All,
My query is like below:
declare @id numeric(17,2) = '123.456'
select @id
Output : 123.46
Expected output is : 123.45
Please help me on this query.
November 22, 2021 at 2:15 pm
So, you are expecting the value to be truncated and not rounded.
Try this
DECLARE @id numeric(17, 2) = ROUND('123.456', 2, 1)
SELECT @id;
November 22, 2021 at 2:16 pm
Change your precision to make the query work as you intend:
declare @id numeric(19,6) = '123.456'
select @id, ROUND(@id,2)
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 22, 2021 at 2:19 pm
Declare @id numeric(17,2) = round(‘123.456’,2,1)
November 22, 2021 at 2:23 pm
No luck sir still i am getting the same result.
declare @id numeric(19,6) = '123.456'
select @id, ROUND(@id,2)
(No column name) (No column name)
123.456000 123.460000
please provide any other alternative way.
November 22, 2021 at 2:30 pm
My mistake. Try these:
declare @id numeric(19,6) = '123.456'
select @id, up = ROUND(@id,2,0), down = ROUND(@id,2,1)
The absence of evidence is not evidence of absence
- Martin Rees
The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
- Phil Parkin
November 22, 2021 at 2:56 pm
Great Thanks.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply