Display two digits after decimal point in SQL Server

Last Reply one year ago By dharmendr

Posted one year ago

Hi!

I used below query, now I want two number after decimal place.

DECLARE @Percent AS TABLE(Id INT,name varchar(10),Price float)
INSERT INTO @Percent VALUES(1,'Apple',10)
INSERT INTO @Percent VALUES(2,'Orange',10)
INSERT INTO @Percent VALUES(3,'Tomato',10)

DECLARE @Detail AS TABLE(Id INT,Price money, IdProduct int)
INSERT INTO @Detail VALUES(1,15,1)
INSERT INTO @Detail VALUES(2,18,2)
INSERT INTO @Detail VALUES(3,25,3)
INSERT INTO @Detail VALUES(4,35,1)

select ((d.Price*p.Price)/100)/12 as result from @Detail d inner join @Percent p on d.IdProduct = p.Id

 

Posted one year ago

Hi PRA,

Use SQL Server ROUND() Function.

SQL

DECLARE @Percent AS TABLE(Id INT,name varchar(10),Price float)
INSERT INTO @Percent VALUES(1,'Apple',10)
INSERT INTO @Percent VALUES(2,'Orange',10)
INSERT INTO @Percent VALUES(3,'Tomato',10)
 
DECLARE @Detail AS TABLE(Id INT,Price money, IdProduct int)
INSERT INTO @Detail VALUES(1,15,1)
INSERT INTO @Detail VALUES(2,18,2)
INSERT INTO @Detail VALUES(3,25,3)
INSERT INTO @Detail VALUES(4,35,1)
 
select ROUND(((d.Price*p.Price)/100)/12,2) as result from @Detail d inner join @Percent p on d.IdProduct = p.Id

Output

result
0.13
0.15
0.21
0.29