Solved

trabslate

Posted on 1998-06-23
4
1,056 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Passing a array as parameter - C 2 105
Problem to show menu 5 98
Acrinis True image 2 111
outlook office 365 8 160
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
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 how to create, access, and change arrays in the C programming language.

696 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