Have you ever met the situation that you get an integer but you really want a double?
For the following method, devide(2,3) will return 0.0.
public static double devide(int x, int y){ return x/y; } |
The problem is that x/y does int division. If you want it to do double division, you can cast one of the operands. Both (double)x/y and x/(double)y will work.
public static double devide(int x, int y){ return (double)x/y; } |
Very often you may want to round a double number. There are multiple ways to do it and the following is a commonly used simple method. If you want to round the result to 2 digits, you can use the following code:
public static double divide(int x, int y){ double z= (double)x/y; double pro = Math.round(z * 100); return pro/100; } |
I’m planning to start my blog soon, but I’m a little lost on everything. Would you suggest starting with a free platform like Word Press or go for a paid option? There are so many choices out there that I’m completely confused
http://www.traininginrajajinagar.in/aws-training-in-rajajinagar
http://www.traininginbtm.in/amazon-web-services-training-in-bangalore/
I just see the post i am so happy the post of information’s.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be subscribing to your feed and I hope you post again soon.I just see
best selenium training institute in hyderabad
best selenium online training institute in hyderabad
Thank you so much for sharing such a wonderful information.
Thanks for posting this useful content, Let me share this, . CCNA training in pune