CAST to DECIMAL in MySQL

From MySQL docs: Fixed-Point Types (Exact Value) – DECIMAL, NUMERIC: In standard SQL, the syntax DECIMAL(M) is equivalent to DECIMAL(M,0) So, you are converting to a number with 2 integer digits and 0 decimal digits. Try this instead: CAST((COUNT(*) * 1.5) AS DECIMAL(12,2))

Rounding down to 2 decimal places in c#

The Math.Round(…) function has an Enum to tell it what rounding strategy to use. Unfortunately the two defined won’t exactly fit your situation. The two Midpoint Rounding modes are: AwayFromZero – When a number is halfway between two others, it is rounded toward the nearest number that is away from zero. (Aka, round up) ToEven … Read more

Convert hex to float

In Python 3: >>> import struct >>> struct.unpack(‘!f’, bytes.fromhex(‘41973333’))[0] 18.899999618530273 >>> struct.unpack(‘!f’, bytes.fromhex(‘41995C29’))[0] 19.170000076293945 >>> struct.unpack(‘!f’, bytes.fromhex(‘470FC614’))[0] 36806.078125 In Python 2: >>> import struct >>> struct.unpack(‘!f’, ‘41973333’.decode(‘hex’))[0] 18.899999618530273 >>> struct.unpack(‘!f’, ‘41995C29’.decode(‘hex’))[0] 19.170000076293945 >>> struct.unpack(‘!f’, ‘470FC614’.decode(‘hex’))[0] 36806.078125

String to decimal conversion: dot separation instead of comma

All this is about cultures. If you have any other culture than “US English” (and also as good manners of development), you should use something like this: var d = Convert.ToDecimal(“1.2345”, new CultureInfo(“en-US”)); // (or 1,2345 with your local culture, for instance) (obviously, you should replace the “en-US” with the culture of your number local … Read more

Culture invariant Decimal.TryParse()

In fact CultureInfo.InvariantCulture can be used here. The parameter expects IFormatProvider, an interface that CultureInfo implements. But InvariantCulture is invariant in the sense that it does not vary with the user’s settings. In fact, there is no culture that accepts either , or . as decimal separator – they are all one or the other. … Read more

C# Decimal.Epsilon

Contrary to that definition, epsilon is actually a concept used to eliminate the ambiguity of conversion between binary and decimal representations of values. For example, 0.1 in decimal doesn’t have a simple binary representation, so when you declare a double as 0.1, it is actually setting that value to an approximate representation in binary. If … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)