T-SQL Simple Two Decimal Places

Posted on 2014-04-11
Last Modified: 2014-04-11

I can't believe that I can't find a simple example of this on the internet, somewhere.

All I want is the number 64.25--not 64 and certainly not 64.00.

The best that I can come up with is the following, and it is giving me 64:


How do I take "UPR30301.MTDHOURS_4/100" and have the result be 64.25?  That's all I want.  It should be very simple.


Question by:TBSupport

Expert Comment

ID: 39994729
if your in SSRS you should be able to simply right click on the field in the form and then press properties and format .... then choose the format tab and enter Format Code as "0.00"
LVL 65

Accepted Solution

Jim Horn earned 500 total points
ID: 39994747
>How do I take "UPR30301.MTDHOURS_4/100" and have the result be 64.25

Open in new window

What you are experiencing is 'integer division', where T-SQL will interpret the division of two integers as a result that is also an integer, hence 5 / 2 = 2 and not 2.5.

To avoid this, you need to CAST either the numerator or the denominator as a decimal, and not the entire result.

T-SQL Integer Division
LVL 33

Expert Comment

ID: 39994755
The problem is the data type precedence. Seems that you're dividing an integer by an integer. Thus the result is integer. The additional cast cannot restore the missing digits as they are not part of the result integer. See

DECLARE @decimal DECIMAL (19,2) = 100;
DECLARE @integer INT = 100;

SELECT	@decimal / 3,		
	@integer / 3,
	@integer / 3.0,
	CAST( @integer / 3.0 AS DECIMAL(19, 2) );

Open in new window

LVL 69

Expert Comment

by:Scott Pletcher
ID: 39994908
CAST(UPR30301.MTDHOURS_4/100.0 AS DECIMAL(18, 2))

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Union 2 queries to a cte (temp table perhaps) 9 36
Query Syntax 17 36
date diff with Fiscal Calendar 4 30
Text file into sql server 5 27
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In a recent question ( here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question