Decimal
Decimal is the name for our common base-ten numeral system
Ieee
IEEE, pronounced "Eye-triple-E," stands for the Institute of Electrical and Electronics Engineers.
Useful precision 64bit
Example |
---|
"Decimal types libraries are fantastic for financial applications because we re used to dealing with the style of rounding required in financial stuff but there is the cost that they tend to be slower than ieee floating point" from question Javascript: Precision strange behavior |
"Most decimal numbers cannot be represented exactly in binary format so they have to be rounded;ieee 754 defines several possibilities for this procedure i think you see this one citation from wikipedia" from question Different rounding results in terms of floating number ending with 5 in C++ |
"Many decimal numbers cannot be represented exactly in this representation;so the compiler uses the nearest available binary ieee floating point number that is available" from question Why does this cast change the result when even VS says it is redundant? |
"The maximum representable value with ieee 754-2008 binary32 is so the base 2 log of a number stored in binary 32 is less than decimal 128" from question Convert number to their log2 "The third line displays the data with the maximum useful precision - an ieee 754 64bit floating-point number has slightly less than 16 decimal digits of precision so all those digits of the literal in math.h are pointless perhaps they can be seen as future-proofing against a possible future redefinition in a format with more precision" from question How to print a double with full precision on iOS? |
Others
Example |
---|
Above number.max_safe_integer for example the precision is less than 0 decimal places to convert a number to a string with a fixed number of decimal places use .tofixed as epascarello suggested as for doing financial calculations some say you should never use ieee 754 floats such as javascript s number s although many of the largest companies in finance do just that from question How to convert a number to float with 8 point decimal places in javascript |
Double has its ieee floating point definition which is also much more complex than decimal from question C# Double.ToString() performance issue |
If an approximate result is good enough and there are lots of calculations where it is you can use double but be aware that it s a binary floating point number and accurate rounding to decimal might not always be possible;although in certain cases it might work in general there is no way to determine force the decimal precision of a double value or indeed any ieee floating point number from question Setting precision for double in java |
Decimal cannot use the fpu;you get best performance with float or real which map to a standard ieee floating point number which is supported by the fpu from question TSQL: Which real number type results in faster comparisons |
Note using parsefloat ieee 754 double precision floating-point means you have a maximum of 52 bits of precision which is a bit more than 15 decimal places from question How to calculate logarithm with base N for big integer? |