Using Large Floats at Higher Precision

edited March 2016 in Questions about Code

I need to use very large floats at high precision. I need 3-4 decimal places with floats at least 8*10^6. I can use an int and a float to get the precision, but it is difficult to do math with those while retaining the precision. I also need to use the values as arguments is several different methods, so how can I do this? Is there a way to increase float precision without having to do this, or a simple way to make it have the required level of precision without heavily modifying the methods I need to use it in?

Tagged:

Answers

  • double?

  • java documentation says that the range for float is

    "float: 4 bytes, IEEE 754. Covers a range from 1.40129846432481707e-45 to 3.40282346638528860e+38 (positive or negative)."

    which should be easily enough for what you say you need

    can you post some code showing your problem?

  • I need 3-4 decimal places with floats at least 8*10^6.

    Does that mean that you have numbers up to 8 milliion with 3 to 4 decimal places?

    In other words something like

    8000000.1234

    this has 11 significant digits i.e. number of digits excluding all leading and trailing zeroes.

    In that case float is not good enough because it only gives you 6-8 significant digits accuracy. You will need to use the double data type that has 14-15 significant digits accuracy.

  • In order to use double type, you also need to replace Processing's math functions w/ Java's Math class:
    http://docs.Oracle.com/javase/8/docs/api/java/lang/Math.html

  • @GoToLoop good point :)

Sign In or Register to comment.