Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calculating numbers

Status
Not open for further replies.

lovekang

Programmer
Joined
Feb 16, 2006
Messages
86
Location
KR

public static void main(String args[]) {
System.out.println(0.1); // 0.1
System.out.println(0.7); // 0.7
System.out.println(0.1 + 0.7); // 0.7999999999999999
}

I expect 0.1, 0.7 and 0.8
why this happens?

thanks.
 
//try this
System.out.println(0.1f + 0.7f); // 0.7999999999999999
 
Thanks.

I'm wondering why this happens?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top