Solved

How can I get the mantissa (integer) portion of a decimal in sql

Posted on 2013-11-25
6
1,005 Views
Last Modified: 2013-11-29
If I have decimal 123456789.456789

How can I get the 123456789 portion of it.
0
Comment
Question by:countrymeister
6 Comments
 
LVL 65

Expert Comment

by:Jim Horn
ID: 39675576
Just cast it as an integer..
SELECT CAST(123456789.456789 as int) 

Open in new window

0
 
LVL 10

Expert Comment

by:GeoffSutton
ID: 39675600
or use the TQSL round:  select round(123456789.456789,0) as result
0
 
LVL 5

Expert Comment

by:Lawrence Barnes
ID: 39675628
Or if you don't want it to round and just want to drop it use this version ofTSQL Round:

SELECT ROUND(123456789.456789, 0, 1) as RoundWithZero
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 10

Expert Comment

by:GeoffSutton
ID: 39675659
Thanks for filling that in, Ivbarnes.  Missed it :)
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 300 total points
ID: 39675827
If you want to truncate, so that 12.99999 became 12, you could also do:

FLOOR(decimal_column)

If you always wanted to round up, so that 12.05 became 13, you could do:

CEILING(decimal_column)
0
 
LVL 5

Expert Comment

by:Lawrence Barnes
ID: 39675843
Huzzah Scott!
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question