how to directly convert char to numbers?

Convert an char array to one float value?

  • hi i have any array of chararctaers that reresent a speed for example char a[3]={0,.,9} i want to convert this array to a float value .. that is float b=0.9 i havea function that convert an array with only number to an integer value i cant find any that would do what i want ??

  • Answer:

    It would help greatly if you tell us which language you are programming in (I will update my answer depending on what language you specify) Edit: Sorry, I don't know C I do know c++ though but that's entirely different isn't it. :( If you know how to use pointers though, I would reccomend finding out what a float consists of as pure memory address and it's usual length. That way you can write directly to the memory. Obviously this isn't safe.

Fatima at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Convert the array into a string. Use a loop and concatenation. Then convert the string to a float. If I knew what language you were using I could offer more help. Additional: char a[3]={'0', '.', '9'}; double f = atof(a); Have fun.

AnalProgrammer

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.