Re: Convert Fraction to Decimal Type
- From: "Dan Guzman" <guzmanda@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 24 May 2009 13:56:57 -0500
As you can see, I'm having to convert part of the prodName column which is a string to integer type. lengthVal is already an integer.
I think the suggestions by Aaron or Erland will work for you. All you need to do is specify a decimal literal instead of integer as one of the expressions. The lengthVal column and CONVERT expression can remain integer.
--
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
"Scott" <sbailey@xxxxxxxxxxxxxxx> wrote in message news:%23SwbMYJ3JHA.1092@xxxxxxxxxxxxxxxxxxxxxxx
I realize that works, but when I run the calculation with column variables inserted, it always returns 0.000000.
Below is my calculation with column values inserted:
((2*(CONVERT(INT, RIGHT(prodName, 1))))/12)* lengthVal
As you can see, I'm having to convert part of the prodName column which is a string to integer type. lengthVal is already an integer.
Any ideas?
"Dan Guzman" <guzmanda@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:Oc6hJRJ3JHA.5728@xxxxxxxxxxxxxxxxxxxxxxxSELECT (CONVERT(decimal(10, 6),((2*4)/12)))
The issue here is that all of the expressions are integers so the result is also integer. Try:
SELECT (2*4)/12.0
--
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
"Scott" <sbailey@xxxxxxxxxxxxxxx> wrote in message news:u7jWzNJ3JHA.4272@xxxxxxxxxxxxxxxxxxxxxxxI need to make a calculated value that translates to
((2*4)/12)
In my code below, I tried using CONVERTand I've even tried DECIMAL format, but I can never display the decimal values of the above formula. I've always used this method when dealing with percents and it worked. What data type must I use to display the formula to 6 digits?
CODE:
SELECT (CONVERT(decimal(10, 6),((2*4)/12)))
.
- References:
- Convert Fraction to Decimal Type
- From: Scott
- Re: Convert Fraction to Decimal Type
- From: Dan Guzman
- Re: Convert Fraction to Decimal Type
- From: Scott
- Convert Fraction to Decimal Type
- Prev by Date: Re: Convert Fraction to Decimal Type
- Next by Date: Re: Test if table exists and drop
- Previous by thread: Re: Convert Fraction to Decimal Type
- Next by thread: Test if table exists and drop
- Index(es):
Relevant Pages
|