MongoDB – What about Decimal type of value?

If you want an exact representation for financial purposes, then doubles or floating point values are unsuitable as the fractional parts are subject to rounding error. Certain decimal values cannot not be represented using binary-based floating points and must be approximated. For a less technical intro, see The trouble with rounding floating point numbers; if … Read more

Best practice for working with currency values in PHP?

As of MySQL v5.0.3, MySQLs DECIMAL datatype stores an exact decimal number, i.e. not an inaccurate floating point representation. To correctly manipulate precision numbers in PHP use the arbitrary precision math functions. Internally this library manipulates text strings. Currency is intended to be stored as a decimal number, you can get units of money smaller … Read more

Clarification on the Decimal type in Python

The Decimal class is best for financial type addition, subtraction multiplication, division type problems: >>> (1.1+2.2-3.3)*10000000000000000000 4440.892098500626 # relevant for government invoices… >>> import decimal >>> D=decimal.Decimal >>> (D(‘1.1’)+D(‘2.2’)-D(‘3.3’))*10000000000000000000 Decimal(‘0.0’) The Fraction module works well with the rational number problem domain you describe: >>> from fractions import Fraction >>> f = Fraction(1) / Fraction(3) >>> … Read more

Conversion of a decimal to double number in C# results in a difference

Interesting – although I generally don’t trust normal ways of writing out floating point values when you’re interested in the exact results. Here’s a slightly simpler demonstration, using DoubleConverter.cs which I’ve used a few times before. using System; class Test { static void Main() { decimal dcm1 = 8224055000.0000000000m; decimal dcm2 = 8224055000m; double dbl1 … Read more

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