How to cast from List to double[] in Java?

With java-8, you can do it this way. double[] arr = frameList.stream().mapToDouble(Double::doubleValue).toArray(); //via method reference double[] arr = frameList.stream().mapToDouble(d -> d).toArray(); //identity function, Java unboxes automatically to get the double value What it does is : get the Stream<Double> from the list map each double instance to its primitive value, resulting in a DoubleStream call … Read more

Converting string to double in C#

There are 3 problems. 1) Incorrect decimal separator Different cultures use different decimal separators (namely , and .). If you replace . with , it should work as expected: Console.WriteLine(Convert.ToDouble(“52,8725945”)); You can parse your doubles using overloaded method which takes culture as a second parameter. In this case you can use InvariantCulture (What is the … Read more

How do I get DOUBLE_MAX?

DBL_MAX is defined in <float.h>. Its availability in <limits.h> on unix is what is marked as “(LEGACY)”. (linking to the unix standard even though you have no unix tag since that’s probably where you found the “LEGACY” notation, but much of what is shown there for float.h is also in the C standard back to … Read more

Convert double to BigDecimal and set BigDecimal Precision

The reason of such behaviour is that the string that is printed is the exact value – probably not what you expected, but that’s the real value stored in memory – it’s just a limitation of floating point representation. According to javadoc, BigDecimal(double val) constructor behaviour can be unexpected if you don’t take into consideration … Read more

Set precision of std::to_string when converting floating point values [duplicate]

There is no way to change the precision via to_string() but the setprecision IO manipulator could be used instead: #include <sstream> template <typename T> std::string to_string_with_precision(const T a_value, const int n = 6) { std::ostringstream out; out.precision(n); out << std::fixed << a_value; return out.str(); }

Convert double to float in Java

Just cast your double to a float. double d = getInfoValueNumeric(); float f = (float)d; Also notice that the primitive types can NOT store an infinite set of numbers: float range: from 1.40129846432481707e-45 to 3.40282346638528860e+38 double range: from 1.7e–308 to 1.7e+308

Moving decimal places over in a double

If you use double or float, you should use rounding or expect to see some rounding errors. If you can’t do this, use BigDecimal. The problem you have is that 0.1 is not an exact representation, and by performing the calculation twice, you are compounding that error. However, 100 can be represented accurately, so try: … Read more

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