0

So, i have column with data type float. i want to take 2 digit after comma

example 0.622 i want the result is 0.62 i already tried some solution from stack overflow but still the result is 0.61.

sum(CASE WHEN a.TOTALBUDGET>bo.Bobot*2 then bo.Bobot*2 else  a.totalbudget end) as UW_Rank
sum(CASE WHEN a.TOTALBUDGET>bo.Bobot*2 then bo.Bobot*2 else  CAST(ROUND(a.totalbudget,2,1)AS NUMERIC(18,2)) end) as UW_Rank_Test

sample data

thanks

Tri
  • 25
  • 1
  • 9
  • please show the tried solution – Squirrel Jul 05 '22 at 03:50
  • https://stackoverflow.com/questions/20119282/how-to-display-two-digits-after-decimal-point-in-sql-server from here, and i have to sum first then take the 2 digit after comma – Tri Jul 05 '22 at 03:51
  • 2
    please edit your question and include the actual query that you have tried. Include any relevant samples data as well – Squirrel Jul 05 '22 at 03:52
  • 2
    How about some sample data ? Best is to create a [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) – Squirrel Jul 05 '22 at 04:07
  • 1
    What you **see** is an artifact of the tool you use to display your resultset and the datatype of the column in question. Rounding can only be part of any solution - it is your tool that is responsible for the display. If you must do this in the query, you will need to also change the datatype as desired using CAST or CONVERT – SMor Jul 05 '22 at 10:50
  • 2
    While asking a question, you need to provide a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example): (1) DDL and sample data population, i.e. CREATE table(s) plus INSERT T-SQL statements. (2) What you need to do, i.e. logic and your code attempt implementation of it in T-SQL. (3) Desired output, based on the sample data in the #1 above. (4) Your SQL Server version (SELECT @@version;). All within the question, no images. – Yitzhak Khabinsky Jul 05 '22 at 12:51
  • problem solved, it must be round first and then sum. thanks all for the advice really appreaciate – Tri Jul 06 '22 at 04:19

1 Answers1

3

Did you tried round function.

declare @val float = '0.622'
SELECT ROUND(@val, 2);
Roshan Nuvvula
  • 803
  • 1
  • 8
  • 28