concatenate float to string asnd get four decimal points

xav056
xav056 used Ask the Experts™
on
Hello
I have two floats with different decimal points some are 3 decimal points and some are 8 decimal points
I haave two float columns in the table and What I would like to do
Is get valuecol(1)-->convert it to varchar(with 4 decimal points, so if the originalvalue is 3 decimal points the converted varchar should be 4 decimal points) then concatenate this to the converted value of col(2) which will be the same format
and finally get both as converted(col1)_Coverted(col2)
For xample:
lets say I have float1= 1234.234
                         float2= -2.345678
I would like to get a string(1234.2340_-2.3456)
How do I do that?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Database Consultant
Top Expert 2009
Commented:
SELECT  CAST( CAST(Float1 as decimal(20,4) ) as varchar ) + '_'+
        CAST( CAST(Float2 as decimal(20,4) ) as varchar)
Commented:
Another one.

select convert(varchar,convert(decimal(20,4),Float1))+'_'+convert(varchar,convert(decimal(20,4),Float2))

Author

Commented:
Is there any reason why you usinf decimal(20,4) not decimal (10,4)?
AneeshDatabase Consultant
Top Expert 2009

Commented:
it depends purely on your data, on the safer side i suggest decimal (20,4)

Author

Commented:
thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial