Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.
Login
Login
OnlineGDB Q&A
Questions
Unanswered
Tags
Ask a Question
Ask a Question
how to take only the int part of a decimal number
+36
votes
asked
Jan 26
by
Luca
(
220
points)
closed
Mar 8
by
Admin
how to take only the int part of a decimal number
closed with the note:
answered
5 Answers
+2
votes
answered
Jan 26
by
Tanvi Jain
(
180
points)
divide number by 1 using int division:
example in python-
num = 17.9
print(int(num/1))
commented
Feb 2
by
Peter Minarik
(
101,340
points)
While your answer is specific to Python (and we do not know what the poster is after), it also does not quite make sense. Why would you need to divide at all? Just create the int:
decimal = 17.9
integral = int(decimal)
print(integral)
Please
log in
or register to add a comment.
+4
votes
answered
Jan 26
by
Peter Minarik
(
101,340
points)
You have various tools from language to language.
What language are you coding in?
What type is your input? What type is your output?
Please
log in
or register to add a comment.
+1
vote
answered
Feb 25
by
Yash Deo
(
160
points)
a=10
b=4
print(a/b)
print(a//b) # here we have use floor division it gives only integer part
output :
2.5
2
Please
log in
or register to add a comment.
+1
vote
answered
Feb 28
by
Tharshan08
(
160
points)
we can use built in functions like round() , floor() , ceil().for exact answer convert int to str and use break statement to terminate the loop
Please
log in
or register to add a comment.
+1
vote
answered
Mar 6
by
clucian programs
(
160
points)
// in c
// to get whole num
float f = 420.69;
printf("%d\n", (int) f);
// to get remainder
printf("%f\n", f - (int)f);
// without using int to convert
printf("%f\n",floor(f));
Please
log in
or register to add a comment.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...