Solved

trabslate

Posted on 1998-06-23
4
1,050 Views
Last Modified: 2011-10-03
I'm working whit bioscom and i´m reading in the screen. But it is a character. How can I translate character to float?

thanks.
0
Comment
Question by:juancarlos
4 Comments
 

Author Comment

by:juancarlos
ID: 1251376
I'm working whit C++ 2.0 in 386
0
 
LVL 2

Expert Comment

by:kellyjj
ID: 1251377
Is the char just a number?  ch="2"   Or is it the actual asci char?
0
 
LVL 84

Expert Comment

by:ozo
ID: 1251378
#include <stdlib.h>
double d = atof("2");
0
 
LVL 4

Accepted Solution

by:
sganta earned 0 total points
ID: 1251379
Hi
You read it as a character string. You store into some character array(string).
Use this function which converts character to float.

float get_float(char test[10]) // or you can give char *test
{
   int j,len,i=0,intpart;
   char ch,ipart[4];
   float num,k,flt;  
   len = strlen(test);
   j=1;
   ipart[0] = '0';
   while (i<len && test[i] != '.')
   {
      ipart[j] = test[i];
      j++;
      i++;
   }

   // Now integer part is get selected
   ipart[j] = '\0';
   intpart = atoi(ipart); /* Or you can use your method to convert into
                             Integer Value */

   num = intpart; /* Or num = (float) intpart; */

   i++;
   k = 1;
   while ( i<len)
   {
     flt = test[i]-48;  /* Or flt = (float)(test[i]-48); */
     k /=10;
     num +=k*flt;
     i++;
   }
     
   return num; // Returns the floating number
}            
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question