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
 Transact-SQL (2000)
 Converting Float to String

Author  Topic 

Debugger
Starting Member

4 Posts

Posted - 2008-02-09 : 02:58:11

Gurus:

I have a float value.. 2343433.33. want to convert into thousand separator (like 2,343,433.33). To do so i am writing writing a function, as i couldn't find any.

When converted value into string, removes .33 value.
can you tell me which function should i use to get float value, with .33 in it?



visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-09 : 03:03:49
I think this should be for a front end requirement and would be best to do it at front end rather than in SQL. which front end are you using? There are numerous functions available which enables you to these formatting easily at front end.
Go to Top of Page

Debugger
Starting Member

4 Posts

Posted - 2008-02-09 : 03:17:12

thanks visakh16.

Requirement is to post it into mobile messaging, and unfortunately there isn't any front like vb in this case. Any idea to do it.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-02-09 : 03:48:08
How you tried to convert to string? did you try using CONVERT()?
Go to Top of Page

Debugger
Starting Member

4 Posts

Posted - 2008-02-09 : 04:09:39

if we take it as procedure:
quote:

Create procedure str_float2(@val2 as float) as
declare
@str1 as varchar(30),
@int1 as integer
set @str1 = convert(varchar(30), @val2)
print @str1
set @int1 = @val2
print @val2

exec str_float2 2343433.33

Result:

2.34343e+006
[varchar]
2.34343e+006 [integer]



Go to Top of Page

Debugger
Starting Member

4 Posts

Posted - 2008-02-09 : 04:22:22


Correction
Create procedure str_float2(@val2 as float) as
declare
@str1 as varchar(30),
@int1 as integer
set @str1 = convert(varchar(30), @val2)
print @str1
set @int1 = @val2
print @int1


exec str_float2 2343433.33

Result:

2.34343e+006
[varchar]
2343433 [integer]






quote:
Originally posted by Debugger


if we take it as procedure:
quote:

Create procedure str_float2(@val2 as float) as
declare
@str1 as varchar(30),
@int1 as integer
set @str1 = convert(varchar(30), @val2)
print @str1
set @int1 = @val2
print @val2

exec str_float2 2343433.33

Result:

2.34343e+006
[varchar]
2.34343e+006 [integer]

Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-02-09 : 09:58:28
I can't beleive I am posting this, but...

declare @f float
set @f=2343433.33
select convert(varchar,convert(decimal(20,2), @f))


elsasoft.org
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-11 : 05:09:06
quote:
Originally posted by jezemine

I can't beleive I am posting this, but...

declare @f float
set @f=2343433.33
select convert(varchar,convert(decimal(20,2), @f))


elsasoft.org


Is this what you wanted to post?

declare @f float
set @f=2343433.33
select convert(varchar,convert(money, @f),1)


Madhivanan

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

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-02-11 : 08:55:18
that works too. i just don't like the idea of returning a numeric type as a string generally, hence the reluctance.


elsasoft.org
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-11 : 09:19:32
<<
i just don't like the idea of returning a numeric type as a string generally
>>

I too

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-11 : 09:23:19
Me three...



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

- Advertisement -