6/7 is 0?

hi.
Am doing a calculation in java.if do 6/7 means the result is 0.since i store the result in double.
After that i perform some calculation using Number Format ,then also same result.
here is my code.
NumberFormat f = NumberFormat.getInstance();
f. setMaximumFractionDigits(2);
String cal2=f.format(6/7);
float cal22=Float.parseFloat(cal2);
System.out.println(cal22);
double db=6/7;
System.out.println(db);Both the above logic giving 0.
Suggest me a thing to do this.
Thanks in advance
regards,
satheeshkannan

duffymo wrote:
Brynjar wrote:
duffymo wrote:
Brynjar wrote:
Unless you cast the numbers to float/double, or add .0, as in 6.0/7.0, the numbers are treated as integers, including the result. Easy to get around, but clumsy nonetheless.Clumsy? Why? Not if you know the difference between integer and floating point numbers.
This is true in any number of languages. It's hardly clumsy, just the nature of integer numbers in computers.
%Maybe just a matter of taste. I'd want automatic float conversion in the OP's case, as he declares the result of the division as a float.Not me. I would be worried about those times when things were going on behind the scenes without me knowing it.
Making one of the arguments a floating point number is an easy thing to do without forcing the compiler to infer anything. Reading minds is asking for trouble.
%That's a good point. While it may feel 'clumsy' to some because it can be inconvenient in the usual case, there's a very good reason why it's this way. I suppose something like this would get picked up as an Xlint warning

Similar Messages

Maybe you are looking for

  • Panel does not start automatically in Gnome 2.24.3

    Since Gnome 2.24.3, the Gnome Panel does not start automatically. I had to manualy add it to the startup group via "Sessions" in order to force it to start when login finishes. Does anybody has the same behavior? Should I report it as a bug?

  • Mixing 4:3 and 16:9 in one dvd project

    I have video that is in the 4:3 style and a 16:9 slideshow - is there anyway I can combine them on one iDvd Project. (It looks like everything should be one way or the other.

  • How to add Image dynamically in Webdynpro ABAP

    Hi Experts, How to add Image dynamically in Webdynpro ABAP. My requirement is i maintain all the images in a table. image source has to pick the table URl dynamically and display. is that possible in webdynpro? and also please give the suggesion, wit

  • Home Directory Synchronisation and "DS_Store" files

    I have five clients on Tiger connected to a Tiger server. All clients are 10.4.8. Initially I turned Home Synchronising on, but since turned it off, realising I don't really need it. One of the clients, with the biggest profile, still keeps synchroni

  • HT4528 problem with imessge network after updating to i07

    Having trouble with iphone 4s after updating to iO7.  imessage won't activate, it says could not sign in.  Please check your network connections. This has been happening since last night.