Author Topic: [Ndless] Converting types  (Read 3573 times)

0 Members and 1 Guest are viewing this topic.

Offline kevinkore3

  • LV3 Member (Next: 100)
  • ***
  • Posts: 57
  • Rating: +0/-0
    • View Profile
[Ndless] Converting types
« 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).

Offline CiriousJoker

  • LV2 Member (Next: 40)
  • **
  • Posts: 34
  • Rating: +1/-0
    • View Profile
Re: [Ndless] Converting types
« Reply #1 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.

Offline Streetwalrus

  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3821
  • Rating: +80/-8
    • View Profile
Re: [Ndless] Converting types
« Reply #2 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.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Re: [Ndless] Converting types
« Reply #3 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.