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:

  1. If my value is 1.27845 and me 2 The answer with decimals is

  2. Rounding down: 1.27
  3. If my value is 33.33333 and I want to reply with 2 decimal places then my answer should be

  4. Rounding UP: 33.34
  5. Rounding Down: 33.33
  6. If my value is 1.27845 and I want to reply with 3 decimal places, then my answer should be

    1. rounding UP: 1.279
    2. Rounding down: 1.278
    3. If my value is 33.33333 and I need a reply with 3 dc

    4. 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.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -