Questions tagged [atof]

atof() is the C runtime library function for converting the ASCII representation of a number to a floating point double.

Use this tag on for all questions about the use of atof() or where it does not seem to be working correctly.

Closely related are:

  • for functions converting text to int, long, or long long
  • for converting to long from text in any base from 2 through 36. Or choose a base automatically as the C compiler does depending on how the number is written. strtoul() converts to an unsigned long.
  • for double
  • for converting one or more values at a time directed by a format specification

SYNPOSIS

#include <stdlib.h>

double atof(const char *nptr);

atof() returns a value of zero if there is any problem during the conversion, though the documentation says that it does not detect errors. Since converting a zero also returns zero, there is no easy way of distinguishing an error from a correct conversion of zero. Use either scanf() or strtod() if error checking is needed.

atof() accepts integers, fixed decimal notation, and scientific notation. Some implementations also recognize the strings INF or INFINITY (disregarding case), NAN (disregarding case) optionally followed by (, a sequence of characters, followed by ). The character string specifies an implementation-dependent type of NAN. (Documentation of these strings are scant.)

Some implementations support hexadecimal formatted floats. These begin with 0x or 0X, followed by at least one hex digit, an optional decimal point (locale-specific), more digits, an optional p or P followed by the binary exponent in hex.

129 questions
0
votes
2 answers

How to send multiple different floating point or decimal values serially to Arduino?

I am trying to send two different decimal values serially to the Arduino. The values which are sent to the Arduino are separated by a comma(,): For e.g. 1.23,4.56 My problem is that when the values are received by the Arduino micro-controller, the…
0
votes
1 answer

atof() not able to read 'e' in 8e-6

I am trying to read type double values from a char buffer word by word. In the file I have some values like 0.032 0.1234 8e-6 4e-3 etc. Here is my code which is using atof() function to convert word (stored in array 's') to a double value num : char…
Jaipreet
  • 45
  • 7
0
votes
1 answer

Unsatisfied Link Error: dlopen failed: cannot locate symbol "atof"?

I am trying to implement the mupdf library to render pdf documents in my app.My app crashes with the following error log:- java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "atof" referenced by "libmupdf_java.so"... …
anup
  • 585
  • 12
  • 34
0
votes
1 answer

convert 2d string array to 1D float ,int arrays

For a project I want to read the columns of a text file in different arrays. First I read the file in one 2D string array and split this array in different int or float 1D arrays. But when I convert the numbers to int of float with the atof or atoi…
josejos41
  • 35
  • 1
  • 1
  • 4
0
votes
2 answers

How to parse numeric strings recieved over TCP

I'm receiving data from my sensor via TCP and the output looks like this: <-0.040000 , -0.005000 , 0,025000 , 0,990000 , -0,000500 , 0.033000 > It's a 6 times double value. I need only first three. Forces in X,Y and Z direction to get their…
Smoky
  • 13
  • 3
0
votes
2 answers

c++ program stop working with atof()

This is my first program on C++. I successfully build it. When I run it, Windows keep giving me program is stop working, the same result that I try to run it with eclipse. Here is my code: #include #include #include…
Serena Qi
  • 121
  • 1
  • 3
  • 11
0
votes
1 answer

Convert char array into double

I have tried this: #include #include int main(int argc, char *argv[]) { FILE *txt1; char tam[13]; char tam1[13]; char tam2[13]; txt1 = fopen("C:/Users/Hugo/Documents/C/in2.txt","r"); if(txt1 == NULL) { printf("No se puede…
0
votes
0 answers

How to add comma separated list of double values into a vector?

I want to take the user's input which will be in this format-- (xx, xx, x) where the x is some arbitrary double value and there is always a comma and whitespace after every value. I've taken this input as a string value to parse it and check if…
0
votes
3 answers

How to convert user input char to Double C++

I'm trying to figure out a method of taking a user input character and converting it to a double. I've tried the atof function, though it appears that can only be used with constant characters. Is there a way to do this at all? Heres an idea of what…
Dozar
  • 71
  • 2
  • 2
  • 6
0
votes
0 answers

Is there any faster and accurate atof?

UPDATE1 So after converting "+49.984367875E-230" to double and converting back to string, how can i print it as "4.998436788E-229" ? As i have to convert "+49.984367875E-230" to double to do comparison. I got a problem when converting string to…
user1024
  • 982
  • 4
  • 13
  • 26
0
votes
1 answer

Arithmetic error with double c++

I have noticed a small error on some arithmetic calculations using double. It is really weird, there's always a small error and/or an extra significant digit. First I am using atof to convert a number that has two significant digits that I am…
Luis Cruz
  • 1,488
  • 3
  • 22
  • 50
0
votes
1 answer

implemented atof that named atof_beta, but the result isn't the same as atof

i wrote a atof function which named atof_beta.i run it, but the result was not the same as atof's result. for example: input:1111111111111111111111111111111111111111111111111111111111111111111111111111111111 output:(fabs(val-atof(s)) <= EPSILON)…
Don7 Hao
  • 11
  • 3
0
votes
2 answers

Scanning, Checking, Converting, Copying values ... How to ? -- C --

Its been a while now and im still trying to get a certain code to work. I asked some question about different commands etc. before, but now I hope this is the final one (combining all questions in one code). I basically want to : *Scan an input…
NLed
  • 1,845
  • 14
  • 39
  • 68
0
votes
3 answers

read long double from a file, then write to another file

i have following part of code: string v; getline(linestream,v,' '); double d=atof(v.c_str()); fprintf(writeFile3,"%f\n",(double)d); but lets say first line has value 0.08012901 but d=0.080129 last 2 values are omitted, how can i get full…
user1450005
  • 53
  • 2
  • 9
0
votes
1 answer

Precision when converting a string decimal number

I need a way to convert this string into its exact number representation. I've tried quite a few things and, from what I know, this should work (famous last words). I'm trying to stay away from installing libraries and I have A LOT of these numbers…
Will Luce
  • 1,781
  • 3
  • 20
  • 33
1 2 3
8 9