Linked Questions
51 questions linked to/from Correct format specifier for double in printf
-5 votes
2 answers
2k views
C++ printing a function's result? [duplicate]
why is that when I print a result from my function, it prints out 0? I tried using a prototype, and followed an example from my teacher, but no dice. Pretty lost here. #define ...
1 vote
1 answer
398 views
Cannot input a double. Why? [duplicate]
I can't scan a double to a variable. This is my code, it is very simple. I built it with command: gcc -Wall -Wextra -Wpedantic -ansi -c double.c #include <stdio.h> int main() { double f; ...
0 votes
1 answer
346 views
Unable to use double variable in C++ using cstdio [duplicate]
C++ code for double using cstdio header. #include <cstdio> using namespace std; int main() { double f; scanf("%lf",&f); printf(...
0 votes
0 answers
59 views
Strange values when adding members in member function [duplicate]
I made two constructors in Vector class. public: Vector() { x = 0; y = 0; z = 0; } Vector(int _x, int _y, int _z) { x = _x; y = _y; z = _z; ...
69 votes
7 answers
454k views
Reading in double values with scanf in c
I try to read-in 2 values using scanf() in C, but the values the system writes into memory are not equal to my entered values. Here is the code: double a,b; printf("--------\n"); //seperate lines ...
45 votes
4 answers
9k views
Why does printf() promote a float to a double?
From a previous question: If you attempt to pass a float to printf, it'll be promoted to double before printf receives it printf() is a variadic function right? So does a variadic function promote ...
10 votes
5 answers
31k views
cocoa - converting a double to string
I have a double number and I would like to convert it to string. The number is, for example, something like 24.043333332154465777... but if I convert it to string using something like NSString *...
7 votes
4 answers
62k views
What's the difference between LONG float and double in C++?
So I know that there's a large difference in the precision of floats and doubles. I get that. Promise. But, in C++, when calling scanf and printf, the notation used to specify a double is "%lf", and ...
7 votes
1 answer
9k views
How to print a single-precision float with printf
I'm trying to print a floating point number in x86_64 assembly but it just prints the value as zero. There's a few questions about this already. One appeared to be resolved by ensuring that you set ...
5 votes
2 answers
8k views
What is wrong with usage of atof function?
int main() { char str[10]="3.5"; printf("%lf",atof(str)); return 0; } This is a simple code I am testing at ideone.com. I am getting the output as -0.371627
3 votes
1 answer
4k views
parsing NSString to Double
so I want to convert NSString to double. I found the following example: NSString * s = @"1.5e5"; NSLog(@"%lf", [s doubleValue]); It works but if doubleValue cannot convert the string to double it ...
1 vote
7 answers
11k views
can someone explain the purpose of %f and %d to me?
#include <stdio.h> int main(int argc, const char * argv[]) { float apples = 1.1; float bananas = 2.2; double fruit = apples + bananas; printf("%f.\n",fruit); return 0;...
9 votes
2 answers
424 views
Why does %f print large values when floating point constants are passed instead of variables?
In the given program why did I get different results for each of the printfs? #include <stdio.h> int main() { float c = 4.4e10; printf("%f\n", c); printf("%f\n", 4.4e10); ...
2 votes
2 answers
1k views
Weird math differences between MSVC and G++
for the whole day I've been fighting with something I believed being a bug but then (with some nasty printf-debugging) it came out that it was a weird exp math function behaviour ... maybe there's ...
3 votes
2 answers
3k views
Code::Blocks does not recognise double identifier (%lf) in a simple C program
Today I decided to recap a bit the C programming language fundamentals and I have encountered this small issue within my Code::Blocks IDE: when I had used the %f format identifier to read and write a ...