Hi
I have value displayed 17125.000000 in sql query . I want to remove 3 zeros from right side
It should display 17125.000
Thanks
Hi
I have value displayed 17125.000000 in sql query . I want to remove 3 zeros from right side
It should display 17125.000
Thanks
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit MohantyRank #112 · 20K reputationPosted Jan 16, 2024, 2:47 AM EST
If your value is varchar then:
DECLARE @yourValue VARCHAR(20) = '17125.000000'; SELECT LEFT(@yourValue, LEN(@yourValue) - 3) AS Result;Amit MohantyRank #112 · 20K reputationPosted Jan 16, 2024, 1:31 AM EST
SELECT CAST(17125.000000 AS DECIMAL(18, 3)) AS Result;You can also use
FORMAT:SELECT FORMAT(17125.020000, '#.000') AS ResultJignesh KumarRank #91 · 22.9K reputationPosted Jan 16, 2024, 1:34 AM EST
Hello Ramco,
Please use this query,
SELECT CONVERT(DECIMAL(18,3),17125.000000)SELECT CONVERT(DECIMAL(18,3),YourColumnName) from YourTableNameRamco RamcoRank #462 · 5.4K reputationPosted Jan 16, 2024, 2:12 AM EST
Hi Jignesh
I am converting this value as varchar . From this i want to remove 3 decimals from right.
Thanks
Jayraj ChhayaRank #304 · 8.2K reputationPosted Jan 16, 2024, 2:37 AM EST
To remove trailing zeros from a value in SQL, you can use the
TRIMfunction along with the0character. Here's an example:SELECT TRIM(TRAILING '0' FROM '17125.000000') AS trimmed_value;In this example, the
TRIMfunction is used to remove the trailing zeros from the value'17125.000000'. The result will be'17125'.If you have a column in a table that contains the value
'17125.000000', you can use the same approach:SELECT TRIM(TRAILING '0' FROM column_name) AS trimmed_value FROM table_name;Replace
column_namewith the actual name of the column andtable_namewith the actual name of the table.By using the
TRIMfunction with theTRAILINGkeyword, you can remove trailing characters from a string. In this case, we are removing the trailing zeros.Jignesh KumarRank #91 · 22.9K reputationPosted Jan 16, 2024, 3:33 AM EST
You can convert it into Varchar(20) from that value as below,
SELECT LEFT(CAST(17125.123000 AS VARCHAR), CHARINDEX('.', CAST(17125.000000 AS VARCHAR)) + 3) AS result;SELECT CONVERT(VARCHAR(20),CONVERT(DECIMAL(18,3),17125.000000))