Results 1 to 6 of 6
Thread: int division
- 03-24-2011, 06:47 PM #1
Member
- Join Date
- Feb 2011
- Posts
- 43
- Rep Power
- 0
int division
I'm not sure of how to work with int while I divide stuff...
I just finished a program that ends up in a presentation of some statistics. There's an issue when I want to display the quota of two integers.
Something like this
Any simple fix to resolve this?Java Code://figures derived in the program. int figureOne = 2; int figureTwo = 3; //in a print method System.out.println("The quota is: " + figureOne/figureTwo);
- 03-24-2011, 06:50 PM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
- 03-24-2011, 06:57 PM #3
Member
- Join Date
- Feb 2011
- Posts
- 43
- Rep Power
- 0
Thank you, it works like a charm!
Is there a way of limiting the number of decimals?
- 03-24-2011, 06:58 PM #4
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
Sure, e.g.
Java Code:System.out.printf("The quota is: %.3f", figureOne/(double)figureTwo);
- 03-24-2011, 07:01 PM #5
Member
- Join Date
- Mar 2011
- Posts
- 94
- Rep Power
- 0
When you divide two integers, the result will be an integer. In other words, you will lose the decimal places. If you want to keep the decimal places, then cast one of them to double (as stated). The other value will get promoted to double and you will get a double result.
- 03-24-2011, 07:10 PM #6
Member
- Join Date
- Feb 2011
- Posts
- 43
- Rep Power
- 0
Similar Threads
-
Issues with Division
By KnotsaboutWood in forum New To JavaReplies: 11Last Post: 01-31-2011, 03:32 AM -
big double division
By grilo in forum Advanced JavaReplies: 4Last Post: 10-11-2009, 10:07 PM -
Problem with division using doubles
By chrismanahan in forum New To JavaReplies: 3Last Post: 10-10-2009, 09:26 PM -
java division and decimal error
By heartysnowy in forum New To JavaReplies: 5Last Post: 10-07-2009, 04:57 PM -
how to discard remainder on division?
By RobertF in forum New To JavaReplies: 9Last Post: 03-13-2009, 12:20 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks