How to round off this number: 3084.08 SQL SERVER?

Asked

Viewed 620 times

-4

How can I round this number: 3084.08 to: 3084.09 in sql server?

  • 1

    Is that round? the lower value is more than two decimal places?

  • There’s no way I can round up the value after the comma?

  • 1

    The amount coming from the bank is this one: 3084.087522295

4 answers

4


You can use the CAST command, example

select CAST(3084.087522295 as numeric (36,2))

3

Use the function ROUND together with CAST of SQL Server:

SELECT CAST(ROUND(3084.087522295, 2) AS NUMERIC(15, 2)) as X

Resulting in 3084.09.


ROUND

Returns a rounded numerical value for the specified length or accuracy.

Syntax

ROUND ( numeric_expression , length [ ,function ] )

Arguments

numeric_expression

Is a Expression of the type category of accurate or approximate numerical data, with the exception of the data type bit.

length

It is the precision for which numeric_expression must be rounded. length must be an expression of type tinyint, smallint or int. When length is a positive number, numeric_expression is rounded to the number of decimal positions specified by length. When length is a negative number, numeric_expression is rounded to the left of the decimal point as specified by length.

Function

This is the type of operation to be executed. Function must be tinyint, smallint or int. When Function is omitted or has a value equal to 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated.


CAST

These functions convert an expression of one data type into another.

  • cast already rounds, but good ;)

  • 1

    @Lucasmiranda truth, I tested now here and really round

0

There is the ROUND function, round to the number of decimal places.

SELECT ROUND(23542351.4154161,2)

SELECT convert(int,(ROUND(23542351.4154161,0)))

-1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.