which data type

which data type

Post by Hi » Sat, 05 Apr 2003 05:38:09



Hi,
Can anyone tell me which data type will give me
2 digits to the right of the decimal point (including
0.00).
The original field is real
So When I do Select Cast (1379.0 / 1000 as decimal (9,2))
I get 1.38 which is what I want
But when I have Select Cast (0.0 / 1000 as decimal (9,2))
I get .00 which doesn't look good.
So to what data type I shoud convert ?

Thanks,
Arik.

 
 
 

which data type

Post by Anith Se » Sat, 05 Apr 2003 05:41:14


For SELECT CAST (0.0 / 1000 AS DECIMAL (9,2)), what do you expect, 0.00?
Better use the client to format the disply you want. In Query Analyzer you
can use STR function like:

SELECT STR(CAST (0.0 / 1000 AS DECIMAL (9,2)), 4, 2)

For more details refer to SQL Server Books Online.

--
- Anith
(Please respond only to newsgroups)

 
 
 

which data type

Post by Steve Kas » Sat, 05 Apr 2003 06:38:51


Arik,

  The way numerical values are displayed cannot be controlled
through the choice of data type.  It is purely an issue of how the
client displays values.  If you want more control over the display,
select character-type values to display.  You may need to use
various string functions, but one possibility is to use str(), which
evaluates to a string expression:

select ltrim(str(<your value>,20,2)) as val ...

Steve Kass
Drew University


>Hi,
>Can anyone tell me which data type will give me
>2 digits to the right of the decimal point (including
>0.00).
>The original field is real
>So When I do Select Cast (1379.0 / 1000 as decimal (9,2))
>I get 1.38 which is what I want
>But when I have Select Cast (0.0 / 1000 as decimal (9,2))
>I get .00 which doesn't look good.
>So to what data type I shoud convert ?

>Thanks,
>Arik.

 
 
 

which data type

Post by arik » Sat, 05 Apr 2003 21:05:06


Thanks Steve,
You've been a great help for me.
>-----Original Message-----
>Arik,

>  The way numerical values are displayed cannot be
controlled
>through the choice of data type.  It is purely an issue
of how the
>client displays values.  If you want more control over
the display,
>select character-type values to display.  You may need to
use
>various string functions, but one possibility is to use
str(), which
>evaluates to a string expression:

>select ltrim(str(<your value>,20,2)) as val ...

>Steve Kass
>Drew University


>>Hi,
>>Can anyone tell me which data type will give me
>>2 digits to the right of the decimal point (including
>>0.00).
>>The original field is real
>>So When I do Select Cast (1379.0 / 1000 as decimal (9,2))
>>I get 1.38 which is what I want
>>But when I have Select Cast (0.0 / 1000 as decimal (9,2))
>>I get .00 which doesn't look good.
>>So to what data type I shoud convert ?

>>Thanks,
>>Arik.

>.