Correct way to use double type to represent money quantities

I was assigned a project where I had to create a class that received money quantities asdouble numbers and that implemented a method returning a quantity of money as double. I have to use this scheme as we have no seen other data types in class.

My question is, what can I do to make sure that the value I'm returning is adouble number that looks like money. For example, I don't want my method to return 10.78889332., I want it to return 10.79. How can I do that? Is there any intended method for that?

Can I let this issue like that and then take care of it in the test class by formating the output of the method when using it. I think this approach is not correct.

Thanks for your time.

[733 byte] By [Camiloa] at [2007-11-26 17:35:05]
# 1

See http://docs.sun.com/source/806-3568/ncg_goldberg.html

There is no correct way to use double type to represent money quantities. You shouldn't be receiving them, you shouldn't use them, and you shouldn't return them. Floating-point is for science, not money.

Use BIgDecimal.

ejpa at 2007-7-9 0:03:06 > top of Java-index,Java Essentials,New To Java...