aspose file tools*
The moose likes Beginning Java and the fly likes can anyone please check my method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can anyone please check my method" Watch "can anyone please check my method" New topic
Author

can anyone please check my method

Bobby Marvikuan
Ranch Hand

Joined: Mar 14, 2012
Posts: 54
In my code there is a problem with a double number and I don't know how to solve that
Here is the method where the problem comes from:

So, in here
gives the value 0.0 whatever the values of x and y. Even if the value of y is 350 heightPixel =0.0. Can anyone help where the problem come from? =/ and second question how to make double to be value with 6 decimal places not only 2 as in this case? Cheers
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1456
    
    5

Hi Bobby Marvikuan,

Welcome to CodeRanch!

The reason is simple. You are doing some division operations before doing round operation.

Hint : a/b = 0 when a and b are int and a < b.

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Bobby Marvikuan
Ranch Hand

Joined: Mar 14, 2012
Posts: 54
Anayonkar Shivalkar wrote:Hi Bobby Marvikuan,

Welcome to CodeRanch!

The reason is simple. You are doing some division operations before doing round operation.

Hint : a/b = 0 when a and b are int and a < b.

I hope this helps.

Thank you so much! But shouldn't double be to 14 decimal points by default ? why it is only to 2? and OK it could be 0 between 0-699 but why when x=700 it is not 1 still 0?=/
Thanks for your answer by the way I get where I did have a mistake
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1456
    
    5

Bobby Marvikuan wrote:and OK it could be 0 between 0-699 but why when x=700 it is not 1 still 0?

Well, as per your for loop, x will always be less than width and y will always be less than height So, if width is 700, maximum value of x would be 699 and 699/700 is 0 in int format

And about decimal points, well, if you are doing operations with double numbers, then yes, rounding off makes sense. But you are already doing operations with int (so, 1/2 would be 0, not 0.5).

I hope this helps.
dennis deems
Ranch Hand

Joined: Mar 12, 2011
Posts: 808
To put it more succinctly, the result of int/int is an int.
Bobby Marvikuan
Ranch Hand

Joined: Mar 14, 2012
Posts: 54
Dennis Deems wrote:To put it more succinctly, the result of int/int is an int.

cheers
Bobby Marvikuan
Ranch Hand

Joined: Mar 14, 2012
Posts: 54
Anayonkar Shivalkar wrote:
Bobby Marvikuan wrote:and OK it could be 0 between 0-699 but why when x=700 it is not 1 still 0?

Well, as per your for loop, x will always be less than width and y will always be less than height So, if width is 700, maximum value of x would be 699 and 699/700 is 0 in int format

And about decimal points, well, if you are doing operations with double numbers, then yes, rounding off makes sense. But you are already doing operations with int (so, 1/2 would be 0, not 0.5).

I hope this helps.

thank you!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can anyone please check my method
 
Similar Threads
please can anyone check the code
program making the whole screen to be blue instead of drawing
mandelbrot casse tete
problem in getPosition and setPosition......
Trying to make a shape.