Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL simple rounding

Query:

declare @a float(10);
declare @b float(10);
declare @c float(10);
set @a = 150.50;
set @b = 19;
set @c = 100;
select @a * @b / @c as result
,ROUND(@a * @b / @c, 2) as rounded

Resulting in:

| result  | rounded  |    
----------------------
| 28.595  | 28.59    |

Should the rounded be 28.60? How do I achieve this?

like image 788
user2463808 Avatar asked Jul 16 '26 19:07

user2463808


1 Answers

I think you can use the following code

declare @a float(10);
declare @b float(10);
declare @c float(10);
set @a = 150.50;
set @b = 19;
set @c = 100;
select @a * @b / @c as result
,FORMAT(ROUND(@a * @b / @c, 1),'N') as rounded

and result set will be;

+--------+---------+
| result | rounded |
+--------+---------+
| 28.595 |   28.60 |
+--------+---------+
like image 106
Esat Erkec Avatar answered Jul 19 '26 11:07

Esat Erkec