x

how to round 2.2875 to 2.29

declare @d decimal set @d='2.2875' select round(@d,0)

i need to round it to 2.29...

more ▼

asked Nov 10, 2010 at 12:00 AM in Default

Murali gravatar image

Murali
906 101 117 120

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

There's 2 issues here:

  1. you haven't defined the decimal with any precision, so by default is defined as decimal(18,0). When you asign 2.2875 to it, it essentially rounds it, giving 2

  2. the second parameter of the round function is the number of decimal places to round to.

so your code needs to be

declare @d decimal (8,2)  --for example  
set @d='2.2875'   
select round(@d,2)

gives

2.29
more ▼

answered Nov 10, 2010 at 12:16 AM

Kev Riley gravatar image

Kev Riley ♦♦
53.2k 47 49 76

thank you...
Nov 10, 2010 at 12:17 AM Murali
(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x987
x6
x6

asked: Nov 10, 2010 at 12:00 AM

Seen: 692 times

Last Updated: Nov 10, 2010 at 01:20 AM