Double precision – decimal places

An IEEE double has 53 significant bits (that’s the value of DBL_MANT_DIG in <cfloat>). That’s approximately 15.95 decimal digits (log10(253)); the implementation sets DBL_DIG to 15, not 16, because it has to round down. So you have nearly an extra decimal digit of precision (beyond what’s implied by DBL_DIG==15) because of that. The nextafter() function … Read more

Convert Java Number to BigDecimal : best way

This is fine, remember that using the constructor of BigDecimal to declare a value can be dangerous when it’s not of type String. Consider the below… BigDecimal valDouble = new BigDecimal(0.35); System.out.println(valDouble); This will not print 0.35, it will infact be… 0.34999999999999997779553950749686919152736663818359375 I’d say your solution is probably the safest because of that.

Why does double in C print fewer decimal digits than C++?

With MinGW g++ (and gcc) 7.3.0 your results are reproduced exactly. This is a pretty weird case of Undefined Behavior. The Undefined Behavior is due to using printf without including an appropriate header, ¹violating the “shall” in C++17 §20.5.2.2 ” A translation unit shall include a header only outside of any declaration or definition, and … Read more

Emulate “double” using 2 “float”s

double-float is a technique that uses pairs of single-precision numbers to achieve almost twice the precision of single precision arithmetic accompanied by a slight reduction of the single precision exponent range (due to intermediate underflow and overflow at the far ends of the range). The basic algorithms were developed by T.J. Dekker and William Kahan … Read more

Are all integer values perfectly represented as doubles? [duplicate]

Disclaimer (as suggested by Toby Speight): Although IEEE 754 representations are quite common, an implementation is permitted to use any other representation that satisfies the requirements of the language. The doubles are represented in the form mantissa * 2^exponent, i.e. some of the bits are used for the non-integer part of the double number. bits … Read more

Adjusting decimal precision, .net

Preserving trailing zeroes like this was introduced in .NET 1.1 for more strict conformance with the ECMA CLI specification. There is some info on this on MSDN, e.g. here. You can adjust the precision as follows: Math.Round (or Ceiling, Floor etc) to decrease precision (b from c) Multiply by 1.000… (with the number of decimals … Read more

Why is 24.0000 not equal to 24.0000 in MATLAB?

The problem you’re having relates to how floating-point numbers are represented on a computer. A more detailed discussion of floating-point representations appears towards the end of my answer (The “Floating-point representation” section). The TL;DR version: because computers have finite amounts of memory, numbers can only be represented with finite precision. Thus, the accuracy of floating-point … Read more

In MATLAB, are variables REALLY double-precision by default?

They’re doubles. vpa() is simply choosing to display non-significant digits beyond the floating point relative accuracy, where printf() and disp() truncate or zero them out. You’re only getting your original four digits back out because the literal you chose to initialize num with just happens to be the exact decimal expansion of a binary double … Read more

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