Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How to remove trailing zeros from a decimal (type) value? Expand / Collapse
Author
Message
Posted Sunday, March 16, 2014 7:18 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, August 21, 2014 6:36 PM
Points: 39, Visits: 76
Hi Everyone,

I would like to 'drop' some trailing zeros from a decimal value, e.g.: 50.000000, and I am wondering how to go about this?

The value is definitely of decimal type, and in this instance I know that I want to eliminate exactly six (6) zeros.

Any help here will be greatly appreciated.

Kind Regards,

David
Post #1551618
Posted Sunday, March 16, 2014 9:32 PM
Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: Yesterday @ 4:10 PM
Points: 346, Visits: 1,391
Normally you should not care about trailing 0's. The front end worries about the display and making it pretty.

But if you have to, this should do it:

Select cast(100/2.0 as decimal(3))



__________________________________________________________________________________________________________
How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/
Post #1551629
Posted Sunday, March 16, 2014 10:46 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, August 21, 2014 6:36 PM
Points: 39, Visits: 76
Thanks LinksUp
Post #1551634
Posted Monday, March 17, 2014 5:39 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Yesterday @ 9:46 AM
Points: 7,224, Visits: 13,696
david.dartnell (3/16/2014)
Hi Everyone,

I would like to 'drop' some trailing zeros from a decimal value, e.g.: 50.000000, and I am wondering how to go about this?

The value is definitely of decimal type, and in this instance I know that I want to eliminate exactly six (6) zeros.

Any help here will be greatly appreciated.

Kind Regards,

David


Cast the value to whichever of the integer datatypes is appropriate.


“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1551692
Posted Tuesday, March 18, 2014 11:55 PM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, August 21, 2014 6:36 PM
Points: 39, Visits: 76
Thanks for your responses.
Post #1552465
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse