I am building a new ecommerce platform using Tomcat/JSTL/MySQL/etc.
I am aware of the various issues related to using floating point calculations - e.g. 12.3456000000000789... I know rounding vs truncation can also be an issue.
Without moving all of the business logic into Java classes, what is the best way to make reliable calculations on currency while still keeping the architecture simple?
My thoughts on possibilities include:
- isolate the problem calculations and deal with them individually
- represent numbers as longs and do calculations using cents
- use BigDecimal and do all calculations in Java
- store numbers in Strings as much as possible
- use <fmt:formatNumber var="... instead of <c:set var="...
I might not be the first to doing this.
What is the most straight forward approach?