String toDouble not working on Teensy?

Status
Not open for further replies.

laptophead

Well-known member
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
 
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?
 
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
 
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
 
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
 
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
 
Status
Not open for further replies.
Back
Top