my_var = (int)my_var;

As simple as that. Basically you don't need it if the variable is int.

Answer from Zach P on Stack Overflow
Discussions

How do I cast my int to float?
To cast a value, you put the destination type in brackets before the value or variable you want to cast, for example (float)x would cast x to a float. However, I assume you're talking about L and S here, in which case just casting won't do you any good since you've declared them as int. They won't be able to hold any decimal places, so casting them to a float would just give you the same wrong number but as a float instead of an int. More on reddit.com
🌐 r/cs50
4
6
October 4, 2021
Converting int to float in C function - Stack Overflow
So I have some source code that needs to be modified to include a 3rd mathematical formula. The source code is: #include int sum_and_diff (int a, int b, int *res) { int sum; ... More on stackoverflow.com
🌐 stackoverflow.com
convert float to integer - C++ Forum
I want 12.345-->12 23.468-->23 i am newbie, i can do it by nearest integer y = floor(x+0.5); but want to learn by other way, prompt In function ‘int main()’: error: expected ‘)’ before ‘int’ More on cplusplus.com
🌐 cplusplus.com
Does C allow implicit casting/conversion from float to an int?
Yes, this sort of conversion is implicitly performed. Behaviour is undefined if the result doesn't fit. More on reddit.com
🌐 r/C_Programming
36
28
November 21, 2020
People also ask

Can float to int conversion be done using functions in C?
Yes, you can create a function that takes a float as input and returns its integer value after applying the desired conversion method.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › programs › float-to-int
How to Convert Float to Int in C? 5 Programs
Can you convert float to int without losing data?
No, some data loss is expected because the decimal part is removed during conversion. To handle this, you may adjust the value before conversion.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › programs › float-to-int
How to Convert Float to Int in C? 5 Programs
Which function is used to round off a float before converting to int?
You can use the round() function from to round a float to the nearest integer before casting.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › programs › float-to-int
How to Convert Float to Int in C? 5 Programs
🌐
WsCube Tech
wscubetech.com › resources › c-programming › programs › float-to-int
How to Convert Float to Int in C? 5 Programs
May 9, 2026 - Learn how to convert a float to an int in C with 5 simple programs. Explore different methods using type casting, floor(), ceil(), and round().
🌐
Medium
medium.com › @brajagopal.tripathi › how-to-convert-any-float-number-to-an-integer-in-c-a6cc59e5f9f5
How to convert any float number to an integer in c? | by Brajagopal Tripathi | Medium
September 20, 2023 - How to convert any float number to an integer in c? There are two ways to convert a float number to an integer in C: Using the built-in int() function. This function will take a float as an input and …
🌐
Quora
quora.com › How-do-I-convert-any-float-number-to-integer-in-c
How to convert any float number to integer in c - Quora
Answer (1 of 23): First, if the non-fractional part of a [code ]float[/code] is representable as an [code ]int[/code], an implicit conversion that “rounds toward zero” (i.e., drops the fractional) exists: [code]int r(float f) { int result = f; return result; // You could just write "return ...
🌐
W3Schools
w3schools.com › c › c_type_conversion.php
C Data Type Conversion
This can be risky, as you might lose control over specific values in certain situations. Especially if it was the other way around - the following example automatically converts the float value 9.99 to an int value of 9:
Find elsewhere
🌐
Jukka Korpela
jkorpela.fi › round.html
How can I convert a floating-point value to an integer in C?
There is no direct tool (like an operator or a library function) for rounding conversion, and strictly speaking a rounding conversion is not a conversion in the same sense that those conversions which are defined in the C standard. For positive floating-point values, the simplest way to achieve a rounding conversion is to use an expression like · (long) (x+0.5) but it is better to be prepared for negative values, even if you do not expect them to occur. This means that one should use the conditional expression · x >= 0 ? (long)(x+0.5) : (long)(x-0.5) The value of this is expression is the integer which is nearest to the value of the floating-point value of x.
🌐
Thiyagaraaj
c-lang.thiyagaraaj.com › archive › c-blog › convert-a-floating-point-value-to-an-integer-in-c
Convert a Floating-point value to an Integer in C - C Programming
you can convert floating point to integer but the straight conversion has some problem.we cannot get the correct value.
🌐
Silicon Cloud
silicloud.com › home › convert float to int in c: guide
Convert Float to Int in C: Guide - Blog - Silicon Cloud
August 5, 2025 - These functions return a float type result that needs to be further converted to an int type. ... Include the math header file and declare a float variable ‘num’ with a value of 3.14. Use the ceilf function to round ‘num’ up to the nearest integer and store it in ‘result’. Use the floorf function to round ‘num’ down to the nearest integer and store it in ‘result2’. Use the roundf function to round ‘num’ to the nearest integer and store it in ‘result3’.
🌐
Carnegie Mellon University
cs.cmu.edu › ~rbd › papers › cmj-float-to-int.html
Danger in Floating-Point-to-Integer Conversion
i = (int)(f + 0.5); C does not round negative numbers down, so values in the interval (-1.5, 0.5) are converted to zero. In contrast, a correct conversion should map only the interval (-0.5, 0.5) to zero. There are several ways to perform rounding for audio, and, surprisingly, proper rounding ...
🌐
Reddit
reddit.com › r/cs50 › how do i cast my int to float?
r/cs50 on Reddit: How do I cast my int to float?
October 4, 2021 -

int main (void)

{

string text = get_string("Text: ");

int Letters = count_letters(text);

int words = count_words(text);

int sen = count_sen(text);

int L = (100/words) * Letters;

int S = (100/words) * Letters;

int index = 0.0588 * L - 0.296 * S - 15.8;

int index1 = round(index);

printf("%i\n", Letters);

printf("%i\n", words);

printf("%i\n", sen);

printf("%i\n", index1);

}

🌐
Medium
medium.com › @ryan_forrester_ › c-float-to-int-conversion-how-to-guide-aea5be6d3d4b
C++ Float to Int Conversion (How To Guide) | by ryan | Medium
January 7, 2025 - - Floats use the IEEE 754 standard, consisting of a sign bit, exponent, and mantissa. This fundamental difference in representation is the root of many conversion challenges. The simplest way to convert a float to an int is through direct casting:
🌐
Onestepcode
onestepcode.com › home
MURAH4D - Situs Game Online GG Soft Resmi Terviral Saat Ini - MURAH4D Indonesia
September 18, 2025 - MURAH4D adalah platform permainan online yang menawarkan pengalaman bermain game tingkat lanjut melalui pilihan penyedia permainan GG Soft, yang dikenal karena stabilitas, kecepatan, dan viral.
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_type_casting.htm
Type Casting in C
If one operand is a float − The ... to float. If any of the operands is double − The result is promoted to double. Integer promotion is the process by which values of integer type "smaller" than int or unsigned int are converted either to int or unsigned int. Consider an example of adding a character with an integer ...
🌐
w3resource
w3resource.com › c-programming-exercises › c-snippets › how-to-convert-a-character-to-an-integer-float-in-c.php
Convert character to integer, float in C
November 1, 2025 - #include <stdio.h> #include <stdlib.h> int main() { char char_array1[] = "45.82734"; float float_value = atof(char_array1); printf("The converted value is: %f\n", float_value); return 0.
🌐
Quora
quora.com › How-do-you-convert-a-float-to-an-integer-using-casting-in-the-programming-language-C
How to convert a float to an integer using casting in the programming language C++ - Quora
Range/overflow: if the float value is outside the target int range, behavior is implementation-defined or undefined for some conversions. Check against numeric_limitswzxhzdk:14::max()/min() when needed. NaN/inf: converting NaN or ±inf to an integer has undefined behavior; guard beforehand.
🌐
Cplusplus
cplusplus.com › forum › beginner › 33018
convert float to integer - C++ Forum
I want 12.345-->12 23.468-->23 i am newbie, i can do it by nearest integer y = floor(x+0.5); but want to learn by other way, prompt In function ‘int main()’: error: expected ‘)’ before ‘int’
🌐
Daniel Lemire's blog
lemire.me › blog › 2020 › 12 › 14 › converting-floating-point-numbers-to-integers-while-preserving-order
Converting floating-point numbers to integers while preserving order – Daniel Lemire's blog
December 14, 2020 - In such cases, an alternative is: uint64_t mask = x & ((uint64_t)1 << 63); return x ^ (mask - 1); ... Very nice indeed. ... Is it possible to compare signed integers with a floating-point compare, or do some bit-patterns not work?