Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Java getting wrong results when subtracting doubles

  Asked By: Navin    Date: Nov 21    Category: Java    Views: 897
  

class test
{
public static void main(String[] args)
{
System.out.println( (1 - 0.85) );
}
}

Result is 0.15000000000000002.

Anyone know why?

Anyone know how I can fix this? I need 2-points after the decimal
place precision.

- Alan.



Original version, same result...
class test
{
public static void main(String[] args)
{
double price = 0.85;
double money = 1;

money = 1 - 0.85;
System.out.println(money);
}
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Java getting wrong results when subtracting doubles Or get search suggestion and latest updates.




Tagged: