Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Rounding in sql and precision to 1

Author  Topic 

Archan144
Starting Member

4 Posts

Posted - 2011-11-02 : 10:24:00
I want to round value to 1 decimal place and show one 0 if decimal points has 00 after decimal.

SELECT ROUND(124.000, 1) return 124.000 but I want 124.0
and
SELECT ROUND(124.2566, 1) returns 124.3000 but I want 124.3

Can I get this in sql?

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-02 : 10:33:12
what you're looking after is

SELECT CAST(124.2566 AS decimal(10,1))
...

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Archan144
Starting Member

4 Posts

Posted - 2011-11-02 : 11:03:42
Thanks for the quick reply, here we are adding restiction to have value of 10 digits which I can't give becuase it's not fixed.

Is there alternate way ?

quote:
Originally posted by visakh16

what you're looking after is

SELECT CAST(124.2566 AS decimal(10,1))
...

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-02 : 11:05:10
quote:
Originally posted by Archan144

Thanks for the quick reply, here we are adding restiction to have value of 10 digits which I can't give becuase it's not fixed.

Is there alternate way ?

quote:
Originally posted by visakh16

what you're looking after is

SELECT CAST(124.2566 AS decimal(10,1))
...

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/






what does that mean? if you want one decimal place why cant you have a fixed scale?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Archan144
Starting Member

4 Posts

Posted - 2011-11-02 : 11:25:19
Below query gives error on execution
SELECT CAST(1245678912.000 AS decimal(10,1))
while
SELECT CAST(124567891.000 AS decimal(10,1))
this works because 124567891 are 10 digits and if we exceed that then it blows up. So I can give fix scale as 1 which I want but that limit of 10 I can't impose.

Thanks in advance.

quote:
Originally posted by visakh16

quote:
Originally posted by Archan144

Thanks for the quick reply, here we are adding restiction to have value of 10 digits which I can't give becuase it's not fixed.

Is there alternate way ?

quote:
Originally posted by visakh16

what you're looking after is

SELECT CAST(124.2566 AS decimal(10,1))
...

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/






what does that mean? if you want one decimal place why cant you have a fixed scale?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-02 : 11:39:41
then give a bigger limit. may be 25

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Archan144
Starting Member

4 Posts

Posted - 2011-11-03 : 09:52:59
Yes, that can be done. Thanks.

quote:
Originally posted by visakh16

then give a bigger limit. may be 25

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-03 : 10:08:46
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -