Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
T-SQL (SS2K5)
»
How to trim the decimal places?
28 posts, Page 1 of 3
1
2
3
»
»»
How to trim the decimal places?
Rate Topic
Display Mode
Topic Options
Author
Message
Nuts
Nuts
Posted Thursday, September 18, 2008 4:38 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Thursday, September 30, 2010 8:02 PM
Points: 155,
Visits: 215
Hi Guys
I have a column with the figures which have 4 decimal points.
I want to trim them to two decimal points.
How do I do it??
Can it be done fron the reporting services as well??
Thanks
Post #572191
bitbucket-25253
bitbucket-25253
Posted Thursday, September 18, 2008 4:57 PM
SSCertifiable
Group: General Forum Members
Last Login: Today @ 7:13 PM
Points: 5,103,
Visits: 20,214
You could use the CONVERT function for example:
DECLARE @Num4 AS DECIMAL(10,4)
DECLARE @Num2 AS DECIMAL(10,2)
SET @Num4 = 1234.9876
SET @Num2 = CONVERT(DECIMAL(10,2),@Num4)
SELECT @Num2
@Num2 will then equal 1234.99 -- note the rounding which has taken place.
of course this works as well
DECLARE @Num4 AS DECIMAL(10,4)
DECLARE @Num2 AS DECIMAL(10,2)
SET @Num4 = 1234.9876
SET @Num2 = @Num4
SELECT @Num2
@Num2 will then equal 1234.99 -- note the rounding
If everything seems to be going well, you have obviously overlooked something.
Ron
Please help us, help you -before posting a question please
read
Before posting a performance problem please
read
Post #572195
Jeff Moden
Jeff Moden
Posted Thursday, September 18, 2008 10:27 PM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 4:51 PM
Points: 32,923,
Visits: 26,811
Much simpler than all that... check out the ROUND function or the STR function (which also right justifies if you need that for a report or file). :)
--Jeff Moden
"
RBAR
is pronounced "ree-bar" and is a "Modenism" for "
R
ow-
B
y-
A
gonizing-
R
ow".
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."
For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #572250
blessybaby
blessybaby
Posted Friday, September 19, 2008 3:38 AM
SSC Rookie
Group: General Forum Members
Last Login: Wednesday, January 23, 2013 2:51 AM
Points: 29,
Visits: 25
Pls try this
DECLARE @Num4 AS DECIMAL(10,4)
SET @Num4 = 1234.9876
SELECT STR(@Num4,Len(@Num4),2)
Post #572359
Madhivanan-208264
Madhivanan-208264
Posted Friday, September 19, 2008 7:59 AM
Old Hand
Group: General Forum Members
Last Login: Wednesday, September 12, 2012 5:17 AM
Points: 329,
Visits: 461
Nuts (9/18/2008)
Hi Guys
I have a column with the figures which have 4 decimal points.
I want to trim them to two decimal points.
How do I do it??
Can it be done fron the reporting services as well??
Thanks
Post some sample data with expected result so that we dont need to guess what you really want
Madhivanan
Failing to plan is Planning to fail
Post #572541
manjunath5581
manjunath5581
Posted Wednesday, May 20, 2009 4:29 AM
Forum Newbie
Group: General Forum Members
Last Login: Saturday, September 22, 2012 1:54 AM
Points: 4,
Visits: 61
Hi,
I want to trim the value of decimal point to 2.
For example
1245.658797
123597.599945
798754.589785
787561.124657
I want this to be displayed as
1245.65
123597.59
798754.58
787561.12
If i try to use decimal(15,2) it will round off the value.
If i convert to type money then also the values get round off
The value type is real in the database
Please help...
Post #720424
arun.sas
arun.sas
Posted Wednesday, May 20, 2009 5:28 AM
Ten Centuries
Group: General Forum Members
Last Login: Thursday, April 19, 2012 10:25 PM
Points: 1,231,
Visits: 3,483
hi,
try this,
create table #temp
(
amount decimal(15,6)
)
insert into #temp
select 1245.658797
union
select 123597.599945
union
select 798754.589785
union
select 787561.124657
select substring((cast(amount as char)),0,(charindex('.',(cast(amount as char)))+3)) amount from #temp
amount
1245.65
123597.59
787561.12
798754.58
ARUN SAS
Post #720442
MTV
MTV
Posted Wednesday, May 20, 2009 5:37 AM
Forum Newbie
Group: General Forum Members
Last Login: Thursday, May 02, 2013 3:58 AM
Points: 3,
Visits: 61
DECLARE @Num4 AS DECIMAL(10,4)
SET @Num4 = 1234.982644
SELECT LEFT(CONVERT(VARCHAR(20),@Num4),CHARINDEX('.',CONVERT(VARCHAR(20),@Num4))+2)
Post #720447
manjunath5581
manjunath5581
Posted Wednesday, May 20, 2009 5:48 AM
Forum Newbie
Group: General Forum Members
Last Login: Saturday, September 22, 2012 1:54 AM
Points: 4,
Visits: 61
Hi Madhu,
When my value is like 1567987.4699987 i got the output as
1567987.47 which is actually rounding off the value
DECLARE @Num4 AS DECIMAL(10,4)
SET @Num4 = 1567987.4699987
SELECT LEFT(CONVERT(VARCHAR(20),@Num4),CHARINDEX('.',CONVERT(VARCHAR(20),@Num4))+2)
And the values specified above are just examples not real values.
Hope i am clear in my explaining the problem.
Post #720458
Ramesh Saive
Ramesh Saive
Posted Wednesday, May 20, 2009 5:49 AM
SSCrazy
Group: General Forum Members
Last Login: Friday, February 22, 2013 12:03 AM
Points: 2,555,
Visits: 2,587
Using ROUND function...
SELECT CONVERT( NUMERIC(18,2), ROUND(1245.65879, 2, 1) )
--Ramesh
Post #720459
« Prev Topic
|
Next Topic »
28 posts, Page 1 of 3
1
2
3
»
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.