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 2005 Forums
 Transact-SQL (2005)
 Remove decimal place for float

Author  Topic 

micnie_2020
Posting Yak Master

232 Posts

Posted - 2009-01-21 : 05:58:46
Dear All,

Have any one have idea how to remove off the decimal place?? My field type is Float

eg:-
1.30 = 1 ticket
1.78 = 1 ticket

I can't use round() or convert(integer,var) because this two will round out my figure. I want to completly to remove the decimal place doesn't care wat is the value after decimal place.

Please Advise.
Thank you.

Regards,
Michelle

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-21 : 06:01:11
select left(13232.30 ,charindex('.',13232.30 ,1)-1)
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-21 : 06:03:37
select cast(1.78 as int)
Go to Top of Page

micnie_2020
Posting Yak Master

232 Posts

Posted - 2009-01-21 : 06:12:43
Both above method are not working.

select left(13232.30 ,charindex('.',13232.30 ,1)-1)
Implicit conversion from data type money to varchar is not allowed. Use the CONVERT function to run this query.


select cast(1.78 as int)
return is 2. But i need the return is 1.

Please advise

Thank you.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-21 : 06:14:15
wt is the datatype of colname

this one also working fine
select left(13232.30 ,charindex('.',13232.30 ,1)-1)

try this also
select floor(1342.83420)
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-21 : 06:15:00
quote:
Originally posted by micnie_2020

Both above method are not working.

select left(13232.30 ,charindex('.',13232.30 ,1)-1)
Implicit conversion from data type money to varchar is not allowed. Use the CONVERT function to run this query.


select cast(1.78 as int)
return is 2. But i need the return is 1.

Please advise

Thank you.



select cast(1.78 as int) output: 1 check it once.
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-21 : 06:17:09
Ok, Welcome
Go to Top of Page

micnie_2020
Posting Yak Master

232 Posts

Posted - 2009-01-21 : 06:20:56
Thank you bklr

Is working fine with Floor.
Thank you very much.

Regards,
Michelle
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-21 : 06:24:39
quote:
Originally posted by micnie_2020

Thank you bklr

Is working fine with Floor.
Thank you very much.

Regards,
Michelle



ur welcome
but check this once
select left(13232.30 ,charindex('.',13232.30 ,1)-1)
it is working fine
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-21 : 06:27:47
quote:
Originally posted by micnie_2020

Dear All,

Have any one have idea how to remove off the decimal place?? My field type is Float

eg:-
1.30 = 1 ticket
1.78 = 1 ticket

I can't use round() or convert(integer,var) because this two will round out my figure. I want to completly to remove the decimal place doesn't care wat is the value after decimal place.

Please Advise.
Thank you.

Regards,
Michelle





convert works for you

select convert(int,1.1324)

o/p is 1

Jai Krishna
Go to Top of Page

bjoerns
Posting Yak Master

154 Posts

Posted - 2009-01-21 : 07:01:05
I'd say floor is better style since the intention is obvious, but cast and floor behave differently:
declare @f float
set @f = -1.78
select floor(@f), cast(@f as int)
Go to Top of Page
   

- Advertisement -