?
Solved

trabslate

Posted on 1998-06-23
4
Medium Priority
?
1,061 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

800 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