How to use float() with small numbers e.g. 1.597065E-37

edited April 2015 in Programming Questions

Hi everyone,

first post! I'm trying to write a simple networking script that works like Daniel Shiffman's scripts here:

http://www.learningprocessing.com/examples/chapter-19/example-19-6/ http://www.learningprocessing.com/examples/chapter-19/example-19-7/

The idea is to send a string of variables seperated by comma, and on the receiving end to split them using splitTokens().

Now I have run into a problem with sending float variables:

String representations of small numbers e.g. 1.597065E-37 won't be converted back using float(), because they contain a character other than a number. https://processing.org/reference/floatconvert_.html

What would be the best way to do this?

Thanks for your help!

Answers

  • Answer ✓

    OK this snippet of code pretty much shows that it's woking. Nevermind.

        String testStr = "1.597065E-37";
        float testFloat = 1.0;
    
        void setup() {
        testFloat = float(testStr);
        println(testFloat); 
        }
    
        void draw() {
          size(200,200);
        }
    
Sign In or Register to comment.