Omnimaga

Calculator Community => TI Calculators => Calculator C => Topic started by: kevinkore3 on June 04, 2014, 09:26:33 pm

Title: [Ndless] Converting types
Post by: kevinkore3 on June 04, 2014, 09:26:33 pm
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).
Title: Re: [Ndless] Converting types
Post by: CiriousJoker on July 19, 2014, 10:03:17 pm
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.
Title: Re: [Ndless] Converting types
Post by: Streetwalrus on July 20, 2014, 02:54:54 am
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.
Title: Re: [Ndless] Converting types
Post by: Matrefeytontias on July 20, 2014, 03:55:24 am
Use the function to print a formatted string into another string, sprintf(char*, const char*, ...);. Example of use :
Code: [Select]
// Make sure your string has enough space
char string[100];
float nb = 374619.716183

sprintf(string, "%f", nb);
Also note that sprintf returns the number of characters that were printed.