Sorry - forgot to mention that I’m using the Photon that I got from Makerfaire SF. I’m assuming that would be using 0.4.0, but let me know if there is a way to check the version of the firmware.
Thanks for the heads-up about sprintf not in 0.4.0 Unfortunately, I can’t get either of your workarounds to work.
Arduino string:
Code
float f = 1.23456;
String sf = (f, 5); // <-- Missing function name?
Serial.println(sf);
###Console
test_float_conv.cpp:11:22: error: invalid conversion from 'int' to 'const char*' [-fpermissive]
delay(2000);
^
In file included from ../inc/spark_utilities.h:31:0,
from ../inc/spark_wiring.h:33,
from ../inc/application.h:29,
from test_float_conv.cpp:2:
../inc/spark_wiring_string.h:67:2: error: initializing argument 1 of 'String::String(const char*)' [-fpermissive]
String(const char *cstr = "");
##With dtoa:
Code
char testStr[20];
double d = 1.23456;
dtoa( d, 2, testStr);
Serial.println(testStr);
Console
^
test_float_conv.cpp: In function 'void loop()':
test_float_conv.cpp:17:21: error: invalid conversion from 'char*' to 'int' [-fpermissive]
String sf = (f, 2);
^
test_float_conv.cpp:17:21: error: too few arguments to function 'char* dtoa(double, int, int, int*, int*, char**)'
In file included from /opt/gcc_arm/arm-none-eabi/include/stdlib.h:11:0,
from ../../core-common-lib/CC3000_Host_Driver/cc3000_common.h:43,
from ../../core-common-lib/SPARK_Firmware_Driver/inc/hw_config.h:35,
from ../inc/main.h:37,
from ../inc/spark_utilities.h:30,
from ../inc/spark_wiring.h:33,
from ../inc/application.h:29,
from test_float_conv.cpp:2:
/opt/gcc_arm/arm-none-eabi/include/stdlib.h:169:8: note: declared here
char * _EXFUN(dtoa,(double, int, int, int *, int*, char**));
^
make: *** [test_float_conv.o] Error 1
It appears that the function signature that you’ve provided is incorrect.
Whichever method is easiest is fine with me.
Thanks!