How to calculate difference in hours (decimal) between two dates in SQL Server?

DATEDIFF(hour, start_date, end_date) will give you the number of hour boundaries crossed between start_date and end_date. If you need the number of fractional hours, you can use DATEDIFF at a higher resolution and divide the result: DATEDIFF(second, start_date, end_date) / 3600.0 The documentation for DATEDIFF is available on MSDN: http://msdn.microsoft.com/en-us/library/ms189794%28SQL.105%29.aspx

How do I convert a decimal to an int in C#?

Use Convert.ToInt32 from mscorlib as in decimal value = 3.14m; int n = Convert.ToInt32(value); See MSDN. You can also use Decimal.ToInt32. Again, see MSDN. Finally, you can do a direct cast as in decimal value = 3.14m; int n = (int) value; which uses the explicit cast operator. See MSDN.

Python “decimal” package gives wrong results

When you construct a Decimal from a floating-point number, you get the exact value of the floating-point number, which may not precisely match the decimal value because that’s how floating-point numbers work. If you want to do precise decimal arithmetic, construct your Decimal objects from strings instead of floating-point numbers: >>> Decimal(‘22.0’) / Decimal(‘10.0’) – … Read more

Raising a decimal to a power of decimal?

To solve my problem I found some expansion series, and them I had them implemented to solve the equation X^n = e^(n * ln x). // Adjust this to modify the precision public const int ITERATIONS = 27; // power series public static decimal DecimalExp(decimal power) { int iteration = ITERATIONS; decimal result = 1; … Read more

round off decimal using javascript

(Math.round((16.185*Math.pow(10,2)).toFixed(1))/Math.pow(10,2)).toFixed(2); If your value is, for example 16.199 normal round will return 16.2… but with this method youll get last 0 too, so you see 16.20! But keep in mind that the value will returned as string. If you want to use it for further operations, you have to parsefloat it 🙂 And now as … Read more

Double vs Decimal Rounding in C#

Why 1/3 as a double is 0.33333333333333331 The closest way to represent 1/3 in binary is like this: 0.0101010101… That’s the same as the series 1/4 + (1/4)^2 + (1/4)^3 + (1/4)^4… Of course, this is limited by the number of bits you can store in a double. A double is 64 bits, but one … Read more

Decimal values with thousand separator in Asp.Net MVC

The reason behind it is, that in ConvertSimpleType in ValueProviderResult.cs a TypeConverter is used. The TypeConverter for decimal does not support a thousand separator. Read here about it: http://social.msdn.microsoft.com/forums/en-US/clr/thread/1c444dac-5d08-487d-9369-666d1b21706e I did not check yet, but at that post they even said the CultureInfo passed into TypeConverter is not used. It will always be Invariant. string … Read more