Calculator Community > Calculator C
[Ndless] Converting types
(1/1)
kevinkore3:
This is probably a stupid question, but how do you convert types with Ndless? I want to convert a float to a character array (I usually use stringstreams).
CiriousJoker:
Can't you just cast it?
if u want to printf it then use %f
Sorry but you have to explain what you want and what doesnt work.
Maybe some example code.
Streetwalrus:
You can't just cast a float into a character array. Try to do that manually, by using the % and / operators and some looping. There's probably a standard library function for that though.
Matrefeytontias:
Use the function to print a formatted string into another string, sprintf(char*, const char*, ...);. Example of use :
--- Code: ---// Make sure your string has enough space
char string[100];
float nb = 374619.716183
sprintf(string, "%f", nb);
--- End code ---
Also note that sprintf returns the number of characters that were printed.
Navigation
[0] Message Index
Go to full version