Click here to Skip to main content
16,022,798 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
SELECT CAST('0.042' AS decimal)*1000


returns value as 0, but i want to display 42, how can i do that

regards
Azeem
Posted
Updated 24-Jun-13 23:58pm
v2

Try
SQL
SELECT FLOOR(CAST('0.042' AS NUMERIC(10,3)) * 1000)
 
Share this answer
 
v2
I suspect that CASTing as Decimal without specifying Precision and Scale results in a Scale of zero which means no decimal places.

These all yield 42 as the result.

SQL
SELECT CAST('0.042' AS decimal(18,3))*1000

SQL
SELECT CAST(0.042 AS decimal(18,3))*1000

SQL
SELECT CAST('0.042' AS numeric(18,3))*1000

SQL
SELECT CAST(0.042 AS numeric(18,3))*1000

SQL
SELECT CAST('0.042' AS real)*1000

SQL
SELECT CAST(0.042 AS real)*1000

SQL
SELECT CAST('0.042' AS float(24))*1000

SQL
SELECT CAST(0.042 AS float(24))*1000
 
Share this answer
 
v2
Try this,,,,,

SQL
SELECT FLOOR(CAST('0.042' AS NUMERIC(10,3)) * 1000)


Regards,
Nirav Prabtani..:)
 
Share this answer
 
SELECT CAST(CAST('0.042' AS DECIMAL(10,3)) * 1000 AS INT)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900