October 25, 2006 at 12:33 pm
I have a decimal column and it contains 1.7325000000 that I want to change that number to be 1.45600CONVERT(NUMERIC(18,3),UnitPriceSell) AS NewUnit
I am trying to use the following convert statement.
CONVERT(NUMERIC(18,3),UnitPriceSell) AS NewUnit
But I am getting the number 1.733 I don't want it to round the numbers. What I actuall want is this 1.7320000000
What am I doing wrong?
vmon
October 25, 2006 at 12:57 pm
declare @decimal decimal(18,10)
set @decimal = 1.7325000000
SELECT SUBSTRING(CAST(@decimal as varchar),1,(CHARINDEX('.',@decimal) + 3)) AS NewUnit
October 25, 2006 at 1:30 pm
Actually rather simple, try this:
round(@value, 3, 1)
happy hunting!
October 25, 2006 at 3:52 pm
Try this:
Select convert (numeric(18,7),unitsellprice) as newunit.
Since you specify the precision value to 3 digits, it rounded the value upto 3 digits.If you want to display the precision value more than 3 , you have to increase the precision value.
October 25, 2006 at 4:19 pm
Prema,
That would work if he wanted 1.7325 to display as 1.7325 as 1.7325. He wanted 1.7325 to display as 1.732 not as 1.733. Using the round function - round(unitsellprice, 3, 1) will return the value 1.732 when unitsellprice is 1.7325.
happy hunting
October 25, 2006 at 10:17 pm
Lynn is absolutely correct... for those that can't find the ROUND function in Books Online here's what the 3rd operand of "1" means...
function
Is the type of operation to perform. function must be tinyint, smallint, or int. When function is omitted or has a value of 0 (default), numeric_expression is rounded. When a value other than 0 is specified, numeric_expression is truncated.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply