Arduino Cannot Convert 'Float' to 'Const Char*' in Initialization

Arduino Cannot Convert 'Float' to 'Const Char*' in Initialization
float diff = 0;
const char* str[] = {"Err: ZPROBE: ",diff};
LCD_ALERTMESSAGEPGM(str);

With the code above I get I get this error. Anyone know how to create a single string from "Err: ZPROBE: " and a (float) diff?

exit status 1
cannot convert 'float' to 'const char*' in initializatio

Sorry should add that in the environment i'm using - 'string' : is not a member of 'std',

Ok now trying this

String str = String("Err: ZPROBE: " , diff);

but get this

call of overloaded 'String(const char [14], float&)' is ambiguous
13

1 Answer

To convert float or double into a string, you can use dtostrf() which is available in the stdlib.h header. Also see the reference of String Object Constructors to construct String objects correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.