Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: String toDouble not working on Teensy?

  1. #1
    Member
    Join Date
    Dec 2016
    Location
    Buena Park ca
    Posts
    63

    String toDouble not working on Teensy?

    Is that true?

    I tried newX = newX_St.toDouble(); and I got a "No class member toDouble"

    Too bad I need the precision,

    I tried the next best thing, ToFloat and it works.
    BUT:

    I can not use the modulo in a float.
    Why not?

    Tried:

    new_Th = newTh_St.toFloat();
    new_Th = new_Th % 90.00;

    and I get:

    invalid operands of types 'float' and 'float' to binary 'operator%'
    new_Th = new_Th % 90.00;

    It worked fine as an integer, but I need the precision.

    Please help.
    Mitch

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    5,755
    Sorry it may help me and others to help you, if you showed a complete example, for example what are new_Th and newTS_St defined as?

  3. #3
    Member
    Join Date
    Dec 2016
    Location
    Buena Park ca
    Posts
    63
    I defined them as doubles, but was impossible to convert from string.

    I also tried define them as Floats, but the modulo operand did not work.

    TNKS

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,178
    In C/C++, the remainder % operator is only defined for use when both operands are integers. You could calculate it yourself for floating point operands and I presume you could even define an overload for the % operator.

    Pete

  5. #5
    To convert a c-string to double try using atof() function. Also %-operator doesn't work with floats (only ints like you found out) but you should use fmod() function

  6. #6
    Member
    Join Date
    Dec 2016
    Location
    Buena Park ca
    Posts
    63
    Thanks everyone
    fmod worked really nice

    new_Th= fmod (new_Th,90); // first is the Number and second is the Factor

    I did not have to ad any library, just added

    #include "math.h". at the top, that has it

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •