Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get 2 digits after decimal point in tsql?

I am having problem to format digits in my select column.I used FORMAT but it doesn't work. Here is my column:

sum(cast(datediff(second, IEC.CREATE_DATE, IEC.STATUS_DATE) as float) / 60) TotalSentMinutes     

I used this:

FORMAT(sum(cast(datediff(second, IEC.CREATE_DATE, IEC.STATUS_DATE) as float) / 60),2) TotalSentMinutes   

ERROR:

'format' is not a recognized built-in function name.

How can I format this calculation?

like image 953
cihadakt Avatar asked May 07 '13 06:05

cihadakt


People also ask

How do you write 2 digits after a decimal point?

Rounding a decimal number to two decimal places is the same as rounding it to the hundredths place, which is the second place to the right of the decimal point. For example, 2.83620364 can be round to two decimal places as 2.84, and 0.7035 can be round to two decimal places as 0.70.

How do I get the after decimal value in SQL?

For bigint use SELECT substr((2.938 % 1)::text,3)::bigint; , else use text result.

How do I get 2 decimal places in MySQL?

SELECT ROUND(-4.535,2); Explanation: The above MySQL statement will round the given number -4.535 up to 2 decimal places.


1 Answers

Try this one -

DECLARE @i FLOAT = 6.677756  SELECT        ROUND(@i, 2)     , FORMAT(@i, 'N2')     , CAST(@i AS DECIMAL(18,2))     , SUBSTRING(PARSENAME(CAST(@i AS VARCHAR(10)), 1), PATINDEX('%.%', CAST(@i AS VARCHAR(10))) - 1, 2)     , FLOOR((@i - FLOOR(@i)) * 100) 

Output:

---------------------- 6,68 6.68 6.68 67 67 
like image 57
Devart Avatar answered Oct 14 '22 23:10

Devart