?
Solved

Printing 12/110*100 always returning 0.0

Posted on 2012-04-02
3
Medium Priority
?
243 Views
Last Modified: 2012-04-12
int x = 12
int y =110

I need to print this either as double or float. It always shows as 0.0
float percentage =(float)(x/y);
0
Comment
Question by:newone2011
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 23

Assisted Solution

by:wdosanjos
wdosanjos earned 750 total points
ID: 37796312
Try:

float percentage = (float)x / y;
0
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 750 total points
ID: 37799290
Since division of two integers (i.e. both nominator and denominator are integers) will only return integer value. Therefore, you may use either wdosanjos's comments or the following:

double percentage = x*1.0/y;
0
 

Author Closing Comment

by:newone2011
ID: 37840075
Good
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses
Course of the Month12 days, 11 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question