Skip to main content
gamedev.net
🔒 Locked

[java] Percent

Started by Spyder Dec 8, 2002 at 5:04 PM 1 replies 650+ views
Original Post
Spyder
Spyder
Whats the best way to calculate percent with two int(s) involved? ie. int x=30; int y=100; System.out.println(x/y+" %"); but working of course...
Petr Stedry
Petr Stedry
Well,

it is enough if you cast just the denominator to float/double.
And this statement
System.out.println((x/(float)y)+" %");

should work as intended (returning a float number with all those decimal places you may ever need).



Petr Stedry
Petr Stedry

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.