I think you are very new to c programming. This is a very simple job. This can be done as:-

float a;
// to input a data in the variable a
scanf("%f",&a);
//to display the stored data
printf("%f\n",a);
//or 
printf("%.nf\n",a);//specify value of n
//maximum value of n is 6 also is its default value
//for e.g. printf("%.2f",a); will display decimal number upto two digits after the decimal place
//you can know more about displaying data as
%d: decimal value (int) 
%c: character (char) 
%s: string (const char *) 
%u: unsigned decimal value (unsigned int) 
%ld: long int (long) 
%f: float value (float or double) 
%x: decimal value in Hexadecimal format 
%o: decimal value in octal format

For avialabe list of formatting specifications go here

Answer from nurakantech on Stack Overflow
🌐
Quora
quora.com › How-do-you-declare-a-variable-as-a-decimal-number-in-the-programming-language-C
How to declare a variable as a decimal number in the programming language C++ - Quora
Answer (1 of 2): A variable does not have a specific base. It just stores the value of the number. It is upto you how you want to interpret the number. [code]int a = 16; // decimal int b = 0x10; // Hexadecimal if (a == b) { std::cout
Discussions

Decimal places
Can you use an integer and add in a decimal point when you display it? A lot of times when software is doing something with money amounts people will just store, say, $15.00 dollars as 1500. You can end up with inaccuracies trying to store these as a float and rounding because floating point numbers are stored as binary and not base 10. More on reddit.com
🌐 r/C_Programming
9
2
September 15, 2018
[C] How can I store a decimal number within an integer variable?
A variable is the type it is, you can't change it. If you want to store a non-integer value you have to use a separate double or float variable. Keep in mind that 25/2 is 12, because the result will be truncated. One of the two operands must be a double to get a double result: double x = 25.0 / 2; double y = c / (double) b; More on reddit.com
🌐 r/learnprogramming
6
1
April 16, 2020
decimal of numbers in c - Stack Overflow
But it doesn't! Please do not consider the else if part when a=2, just check out the a=1. ... @BerkDemir You need to be more specific about your problem, like your input, output and expected output. ... You declared b as float and taking input as a decimal & later printing both float b,c as decimal? More on stackoverflow.com
🌐 stackoverflow.com
scanf - Input decimal numbers in C - Stack Overflow
I am extremely beginner in programming language. so i am facing some problems. please help me out. Is it possible to take input a floating or double number with 2 digits after the decimal point usi... More on stackoverflow.com
🌐 stackoverflow.com
🌐
W3Schools
w3schools.com › c › c_data_types_numbers.php
C Numeric Data Types
C Examples C Real-Life Examples C Exercises C Quiz C Code Challenges C Compiler C Syllabus C Study Plan C Interview Q&A C Certificate ... Use int when you need to store a whole number without decimals, like 35 or 1000, and float or double when ...
🌐
IBM
ibm.com › docs › en › zos › 2.5.0
Decimal data types in C
We cannot provide a description for this page right now
🌐
IBM
ibm.com › docs › en › zos › 2.4.0
Using decimal data types in C
We cannot provide a description for this page right now
Find elsewhere
🌐
Reddit
reddit.com › r/c_programming › decimal places
r/C_Programming on Reddit: Decimal places
September 15, 2018 -

Can I create a variable and set it to a specific decimal place? For example "float z to 5 dp" where z would be recorded to 5 dp for the rest of the program

🌐
GeeksforGeeks
geeksforgeeks.org › c language › g-fact-41-setting-decimal-precision-in-c
Setting decimal precision in C - GeeksforGeeks
January 10, 2025 - // C program to set precision in floating point numbers // using format specifier #include<stdio.h> int main() { float num = 5.48958123; // 4 digits after the decimal point printf("%0.4f", num); return 0; }
🌐
Reddit
reddit.com › r/learnprogramming › [c] how can i store a decimal number within an integer variable?
r/learnprogramming on Reddit: [C] How can I store a decimal number within an integer variable?
April 16, 2020 -

Hi! I'm learning to use operators and my handoobk used this program to explain them:

#include <stdio.h>

int main(void) {

/* Variables */

int a =100; b =2; c =25; d =4; result;

result = a - b; //substraction

printf ("a - b = %i\n", result);

}

But what if I want to operate result= c/b and then display it? How can I store the result of 25 / 2 in a variable that has been defined as an int type? Changing the variable type to floator doublemid program resulted in an error, and changing its type throughout the program displayed a 0 on all the operations.

🌐
Linux Hint
linuxhint.com › setting_decimal_precision_c_-language
Setting Decimal Precision in C – Linux Hint
In the printf() function or one of its variants, the fit parameter is a dot followed by the number of decimal digits to specify for precision. The following snippet shows how to set the decimal precision to thousandths using the format field of printf(): ... The following code declares the ...
🌐
Northern Michigan University
nmu.edu › Webb › ArchivedHTML › MathComputerScience › c_programming › c_008.htm
More About Float and Double Variables
SPECIAL NOTE ABOUT DATA TYPE CONVERSION Consider the following program, #include <stdio.h> main() { int value1 = 12, value2 = 5; float answer = 0; answer = value1 / value2; printf("The value of %d divided by %d is %f\n",value1,value2,answer ); } Sample program output The value of 12 divided by 5 is 2.000000 · Even though the above declaration seems to work, it is not always 100% reliable.
🌐
Stack Overflow
stackoverflow.com › questions › 19079238 › decimal-of-numbers-in-c
decimal of numbers in c - Stack Overflow
#include<stdio.h> int main() { float b,c,; int a,kk; printf("Welcome to the unit conversion program\n"); printf("This program can convert the measurements of;\n"); printf("1-Length\n"); printf("2-Mass\n"); printf("Please select the number that corresponds to the measurement you want to convert in:\n"); scanf("%d",&a); if (a==1){ printf("Your number will be converted from inches to centimeters.\n"); printf("Please enter the length.\n"); scanf("%f",&b); c=b*2.54; printf("%f inch is %f cm.",b,c); scanf("%d",kk); \. to avoid to shut the cmd windows .\ } else if (a==2){ printf("Your number will be
🌐
W3Schools
w3schools.com › c › c_data_types_dec.php
C Data Types Decimal Precision
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT SWIFT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING HTML & CSS BASH RUST TOOLS ... Create Variables Format Specifiers Change Values Multiple Variables Variable Names Real-Life Examples Code Challenge C Data Types · Data Types Characters Numbers Decimal Precision Memory Size Real-Life Example Extended Types Code Challenge C Type Conversion C Constants C Operators
🌐
Quora
quora.com › How-do-I-write-function-in-C-that-will-add-decimal-numbers-who-have-point-on-different-places
How to write function in C that will add decimal numbers who have point on different places - Quora
Answer (1 of 3): (After reading details in the comment.) Without knowing what [code ]Number_t[/code] looks like it’s impossible to answer this question, but from the sample snippets I can guess how it should behave. [code]// This is just a guess. typedef struct __number_t { int exponent; un...
🌐
Quora
quora.com › How-do-you-write-a-C-program-that-will-take-a-decimal-number-and-if-it-has-any-value-except-zero-in-the-decimal-place-then-it-will-print-it-otherwise-it-will-only-print-the-integer-part
How to write a C program that will take a decimal number, and if it has any value except zero in the decimal place then it will print it, otherwise it will only print the integer part - Quora
Answer (1 of 6): Re “How do you write a C program”: By doing your own programming instead of grubbing for cheats on Quora. Re “that will take a decimal number”: There is no such thing as “a decimal number”. Did you mean “a decimal representation of a real number”? But computers don’t store real ...
🌐
YouTube
youtube.com › watch
Setting Decimal Precision in C - YouTube
Setting Decimal Precision in CGreetings, in this C tutorial we shall be looking at how to specify how many decimal places we print out for a float or double ...
Published   July 15, 2023
🌐
Reddit
reddit.com › r/computerscience › efficiently use decimal numbers in c
r/computerscience on Reddit: Efficiently use decimal numbers in C
March 2, 2022 -

TL;DR: Can someone point me to research on very efficient decimal number manipulation and interoperability with floats and ints, written in the C language?


Sorry for the wall of text, but I want to give the full background here. As most of you know, floating point numbers are a pain when you need a certain level of exact mathematical calculations.

For example, .1 + .2 - .3 equals zero, but not for most programming languages (static languages, for varying definitions of static tend to have this issue, too):

$ perl -E 'say .1+.2-.3'
5.55111512312578e-17
$ ruby -e 'puts 0.1 + 0.2 - 0.3'
5.551115123125783e-17
$ python -c 'print .1 + .2 - .3'
5.55111512313e-17
$ echo "puts [expr .1+.2-.3]"|tclsh
5.551115123125783e-17

Those are very small numbers, but they're not zero. If you divide the mass of the sun by those values of "zero", you get something which is roughly the mass of Mount Everest. You want an exception instead.

For any of you working on financial systems, you know about converting floats to ints, doing math on them, and converting them back, but it's a pain:

$ python -c 'print (10*.1 + 10*.2 - 10*.3)/10'
0.0

Then there's Raku's approach:

$ rakudo -e 'say .1+.2-.3'
0

The last example from the Raku programming language looks interesting, but it's not using decimal numbers. It's using rationals:

$ rakudo -e 'say (.1+.2-.3).WHAT'
(Rat)

That looks pretty cool, but as soon as you get something that can't be represented as a rational (numerator over denominator), such as the square root of 2, it falls back to Num, a floating point:

$ rakudo -e 'say (.5+1.5).WHAT'
(Rat)
$ rakudo -e 'say (.5+1.5).sqrt.WHAT'
(Num)

With decimal numbers, I could specify an arbitrary precision and I'll get a decimal number back. Some languages offer built-in classes to support this, such as java.math.BigDecimal in Java, or decimal.Decimal in Python. However, there's a catch: they're classes that wrap native numbers, not direct native support for decimals.

What many people don't know is that COBOL not only offers native decimal number support, but COBOL to Java conversions sometimes fails because Java simulates this at the language level, not the compiler level. As a result, I've read about COBOL to Java conversion projects that failed because Java implementations were often slower than their COBOL counterparts. This is a massive problem when dealing with millions of dollars of financial transactions in a batch process. Those errors add up, so using decimals minimizes errors, but at the cost of performance.

It's also worth noting that many mainframes have native hardware support for decimal numbers, something COBOL takes advantage of, but most languages do not.

I was recently investigating introducing a native decimal type to the Perl programming language, but while some interest was expressed, I couldn't provide decent background on extremely efficient implementations. Having a native decimal type would be a huge boon for producing programs that need very accurate math. Can someone offer suggestions on where to go for more information?