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?
//figures derived in the program.
int figureOne = 2;
int figureTwo = 3;
//in a print method
System.out.println("The quota is: " + figureOne/figureTwo);
One of them must be a double!
Originally Posted by überfuzz
System.out.println("The quota is: " + figureOne/(double)figureTwo);
Thank you, it works like a charm!
Is there a way of limiting the number of decimals?
System.out.printf("The quota is: %.3f", figureOne/(double)figureTwo);
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.
Poker - I figure that one out. I've been messing about with type dynamic languages for to long, I guess.