sql - Rounding up and down of numbers with specific decimal points -
I am using SQL Server 2008 R2 and round the values with specific decimal points as shown below and below For example:
-
If my value is 1.27845 and me 2 The answer with decimals is
- Rounding down: 1.27
If my value is 33.33333 and I want to reply with 2 decimal places then my answer should be
- Rounding UP: 33.34
- Rounding Down: 33.33
If my value is 1.27845 and I want to reply with 3 decimal places, then my answer should be
- rounding UP: 1.279
- Rounding down: 1.278
If my value is 33.33333 and I need a reply with 3 dc
- Riding down: 33.333
I am looking for all matters Valid solution should be thanked ...
You can use the following "offset" with FLOOR and CEILING
DECLARE @ Digit Int = 2, Avilue Decimalian (10,5) = 1.27845 DECLARE @calc_scale int = POWER (10, @ points) Choose Cast (Flow (@value * @calc_scale) / @ calc_scale
However, below the target data as DCC (10,5), CAST (CEVLING (@value * @calc_scale) / @ calc_scale AS DCIML (10,5) is always specified in the query (e.g. Edit : C above A example of scale 5) You can not dynamically change the number of digits in the output, because it depends on the data type of scale variable. You can mess with the conversion of a VARCHAR data type and trim the unwanted numbers, but I am strongly voting against it.
If you only need to display the number of significant digits, then I recommend trimming the application layer.
- Rounding down: 1.278
- Rounding down: 1.27
Comments
Post a Comment