Solved

Printing 12/110*100 always returning 0.0

Posted on 2012-04-02
3
239 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
3 Comments
 
LVL 23

Assisted Solution

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

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

Accepted Solution

by:
Peter Kwan earned 250 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 159
Where to store the queries for modification of table 4 61
eclipse argument 14 60
runtime exception 2 27
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

785 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