September 21, 2010 at 11:53 am
How to round up a number and trim it to two digits, exe 1.434567 to 1.4
September 21, 2010 at 1:18 pm
Round up? If you round 1.434567 up, it'll be 1.5, not 1.4.
Can you clarify your requirement?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 21, 2010 at 1:41 pm
i have a row of data with numbres like 1.43467,..,... and i want a sql code that can make it 1.4
September 21, 2010 at 1:52 pm
What do you want to happen to numbers like this:
1.45
1.48
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
September 21, 2010 at 2:06 pm
Congratulations on 20k, Gail. 🙂
saimddr:
The question is whether or not you want to round the data or truncate the data.
Rounding the data can increase or decrease its value.
Truncating the data just chops off everything after the specified position.
You can get either result with the ROUND() function.
declare @data float
set @data = 1.4632
select round(@data,1,0) as rounded, round(@data,1,1) as truncated
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
September 21, 2010 at 2:06 pm
no matter how big is the number i want first 2 digits
September 21, 2010 at 2:11 pm
That would be truncation.
Will you ever have numbers like 14.567 or 143.953?
If so, do you want the answer to be 14?
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
September 21, 2010 at 2:12 pm
saimddr (9/21/2010)
no matter how big is the number i want first 2 digits
So,
123 is 12
123.987 is 123.9
0.91 is 0.9
.123 is .12?
Or, are you really after something like, get rid of everything past the first decimal place?
-- Cory
September 21, 2010 at 2:14 pm
123.987 is 123.9
????
Cory, explain please.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
September 21, 2010 at 2:19 pm
until we have some clarification and examples...here's an idea
suggest looking up "ROUND" in BOL
SELECT CAST(Round (1.434567, 1,1) AS DECIMAL (18, 1))
SELECT CAST(Round (1.4499999999, 1) AS DECIMAL (18, 1))
SELECT CAST(Round (1.450000000, 1) AS DECIMAL (18, 1))
SELECT CAST(Round (14.47, 1,1) AS DECIMAL (18, 1))
SELECT CAST(Round (1456666.4, 1,1) AS DECIMAL (18, 1))
________________________________________________________________
you can lead a user to data....but you cannot make them think
and remember....every day is a school day
September 21, 2010 at 2:19 pm
The Dixie Flatline (9/21/2010)
123.987 is 123.9
????
Cory, explain please.
I was adding more examples to try and get the true requirement. 123.987, is that supposed to be 123.9? Make sense?
-- Cory
September 21, 2010 at 2:33 pm
September 21, 2010 at 3:05 pm
You spin me round round, baby, right round....
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
September 21, 2010 at 11:28 pm
The Dixie Flatline (9/21/2010)
You spin me round round, baby, right round....
😀 Lol,Bob
September 22, 2010 at 6:51 am
Thanks to all for the help.......
declare @x decimal(10, 4)
set @x = 3.4567
select @x, cast(@x as decimal(10, 1))
Viewing 15 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply