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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 FRAC function

Author  Topic 

mbelda
Starting Member

1 Post

Posted - 2008-02-08 : 04:03:20
I need a function FRAC in Transact SQL, y have a money value and y need decimal part of value,

value 15.24 $

I need function return value 24

Thanks

Manuel Belda
informatica@ilidexsa.es

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2008-02-08 : 04:32:56
Quick and dirty. Although , if you are planning on doing complicated mathematical functions , I would recommend you use C#

DECLARE @money VARCHAR(10)
SET @money = '15.24'
SELECT SUBSTRING(@money,CHARINDEX('.',@money,0)+1,LEN(@money))

Jack Vamvas
--------------------
Search IT jobs from multiple sources- http://www.ITjobfeed.com
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-08 : 04:47:30
SELECT value-FLOOR(value) AS FractionalPart FROM table
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-09 : 02:14:56
Ohhh.. What about negative numbers?



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-09 : 03:41:31
SELECT ABS(value-
CASE WHEN value >0 THEN FLOOR(value)
WHEN value<0 THEN CIELING(value)
ELSE 0
END)
AS FractionalPart FROM table
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-02-11 : 02:30:42
[code]select (convert(int, value * 100)) % 100[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-11 : 04:46:47
quote:
Originally posted by khtan

select (convert(int, value * 100)) % 100



KH
[spoiler]Time is always against us[/spoiler]





Truncated result

select (convert(int, 12.4565 * 100)) % 100

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -