November 8, 2005 at 1:42 pm
Hi People,
I have values like this:
125,4587878
1,369888
15487,9887
I just need two numbers after ',', but I dont want round the value.
125,45
1,36
15487,98
Please, help me..
Thanks
November 8, 2005 at 1:53 pm
SELECT CASE WHEN CHARINDEX(',', @value) > 0 THEN LEFT(@value,CHARINDEX(',', @value)+2) ELSE @value END
November 8, 2005 at 1:55 pm
It's recommended to open BOL time to time (press F1)
This example uses two SELECT statements to demonstrate the difference between rounding and truncation. The first statement rounds the result. The second statement truncates the result.
Statement | Result |
---|---|
|
|
|
|
In your case : ROUND(Value, 2, 1)
_____________
Code for TallyGenerator
November 8, 2005 at 1:56 pm
G'Day,
DECLARE @TestString VARCHAR (25),
@TestNum DECIMAL(20,10)
SET @TestNum = 125.4587878
SET @TestString = CAST(@TestNum AS VARCHAR)
SELECT @TestString, LEFT(@TestString,CHARINDEX('.',@TestString)+2)
SET @TestNum = 1.369888
SET @TestString = CAST(@TestNum AS VARCHAR)
SELECT @TestString, LEFT(@TestString,CHARINDEX('.',@TestString)+2)
SET @TestNum = 15487.9887
SET @TestString = CAST(@TestNum AS VARCHAR)
SELECT @TestString, LEFT(@TestString,CHARINDEX('.',@TestString)+2)
Hope this helps
Wayne
November 8, 2005 at 2:07 pm
Thanks a lot 🙂
November 8, 2005 at 4:49 pm
For some reason people prefer to use slow and not reliable (locale dependable - will not work with $12,050.25) solutions and ignore proper ones.
_____________
Code for TallyGenerator
November 9, 2005 at 9:10 am
Why do you think I don't hang out here anymore?!?!
November 9, 2005 at 11:53 am
Oh no, Remi say it isn't so.
November 9, 2005 at 11:58 am
Ten years ago I don't think the truncate feature exisited (sysbase). I gave up looking. Sergiy, thanks so much for posting. I wonder how long the truncate feature has been there?
Thanks again,
ron
November 9, 2005 at 12:32 pm
Check my recent post count if you need a confirmation .
Viewing 10 posts - 1 through 9 (of 9 total)
You must be logged in to reply to this topic. Login to reply