From your question it seems like you are using C99, as you have used %lf
for double.
To achieve the desired output replace:
sprintf(aa, "%lf", a);
with
sprintf(aa, "%0.7f", a);
The general syntax "%A.B"
means to use B digits after decimal point. The meaning of the A
is more complicated, but can be read about here.
Related Posts:
- What causes a segmentation fault (core dump) to occur in C?
- uint8_t vs unsigned char
- How to use symbols of extended ASCII table in C?
- What is the difference between ++i and i++?
- Using boolean values in C
- What does “collect2: error: ld returned 1 exit status” mean?
- typedef struct vs struct definitions [duplicate]
- What can be the reasons of connection refused errors?
- typedef struct vs struct definitions [duplicate]
- What is newline character — ‘\n’
- Why does ENOENT mean “No such file or directory”?
- Cannot figure out how to use getchar(); in C
- Why am I getting “void value not ignored as it ought to be”?
- 1 = false and 0 = true?
- c stack smashing detected
- char *array and char array[]
- Convert char to int in C and C++
- Get a substring of a char*
- What causes the Broken Pipe Error?
- Strings and character with printf
- Why does the terminal show “^[[A” “^[[B” “^[[C” “^[[D” when pressing the arrow keys in Ubuntu?
- Why is the gets function so dangerous that it should not be used?
- Write to .txt file?
- What does “collect2: error: ld returned 1 exit status” mean?
- Warning comparison between pointer and integer
- What does #pragma once mean in C? [duplicate]
- Using ssize_t vs int
- Why a warning of “control reaches end of non-void function” for the main function?
- Connect: Socket operation on non-socket
- “Initializer element is not constant” in C
- How do you do exponentiation in C?
- Printing long int value in C
- Undefined reference to pow( ) in C, despite including math.h [duplicate]
- C read file line by line
- No Symbol Table using GDB on Compiled Programs
- Try catch statements in C
- What is char ** in C?
- How do I create an array of strings in C?
- How to check if a string is a number?
- The difference between stdout and STDOUT_FILENO
- where does stdio.o live in linux machine?
- Using Dynamic Memory allocation for arrays
- Python ? (conditional/ternary) operator for assignments
- conflicting types error when compiling c program using gcc
- Get the current time in C
- What’s the difference between a file descriptor and file pointer?
- error: indirection requires pointer operand (‘int’ invalid)
- What is a file with extension .a?
- What is the difference between exit(0) and exit(1) in C?
- Cygwin – Makefile-error: recipe for target `main.o’ failed
- error: indirection requires pointer operand (‘int’ invalid)
- Why am I getting “undefined reference to sqrt” error even though I include math.h header?
- Why am I getting “undefined reference to sqrt” error even though I include math.h header?
- Finding the length of a Character Array in C
- Return char[]/string from a function
- Expected declaration specifier error in function
- Valgrind: Invalid read of size 1
- Multiple definition of … linker error
- Does sizeof return the number of bytes or the number of octets of a type in C?
- Zero an array in C code
- Passing an array by reference in C?
- Excess elements in char array initializer error
- Encrypt with private key and decrypt with public key
- Warning: return from incompatible pointer type in C
- How to generate a random number between 0 and 1?
- strcmp giving segmentation fault
- What does “pointer being freed was not allocated” mean exactly?
- How to use timer in C?
- C char* to int conversion
- What is the difference between stdin and STDIN_FILENO?
- Memory Clobbering Error
- Check if input is integer type in C
- Iterate through a C array
- Allocating string with malloc
- How to simply convert a float to a string in c?
- What is the difference between char array and char pointer in C?
- hash function for string
- double free or corruption (!prev) error in c program
- What happens during a “relocation has invalid symbol index” error?
- What does this GCC error “… relocation truncated to fit…” mean?
- Using floats with sprintf() in embedded C
- Printf width specifier to maintain precision of floating-point value
- Two or more data types in declaration specifiers error
- Error: “Access not within mapped region at address” (Valgrind)
- printf format specifiers for uint32_t and size_t
- How to convert string to float?
- What is an simple example of copy_from_user
- What is `S_ISREG()`, and what does it do?
- typedef struct pointer definition
- How does the fscanf function work?
- Math constant PI value in C
- The code does not execute properly. Try to figure out why
- ld.exe: cannot open output file … : Permission denied
- How to read from input until newline is found using scanf()?
- getline() vs. fgets(): Control memory allocation
- What’s the difference between “mod” and “remainder”?
- What is char ** in C? [duplicate]
- segmentation fault using scanf
- Segmentation fault- strcat
- segmentation fault with strcpy [duplicate]