BigDecimal result = new BigDecimal(10).divide(new BigDecimal(3));
I find the actual output slightly outside of my predicted pool of predicted behavour:
Exception in thread "main" java.lang.ArithmeticException : Non-terminating decimal expansion; no exact representable decimal result.
The logic thing to me given the operation would be to use defaults ( preferably controllable ones ), not to produce occasional errors that can confuse hell out of a beginner.
at least it's documented (Score:2)
to be fair, this behavior is in the Javadocs :-)
I'm ambivalent about implementing defaults. I think one of the reasons you use a BigDecimal over a float is that you want precision, like when manipulating money. Forcing you to then specify that precision (with a scale and rounding mode) isn't that far out of bounds.
But you're right that beginners might not be aware of these trade-offs. Maybe they're just grabbing numberic fields out of a database and they're automatically mapped to BigDecimals...
but still mis-sold? (Score:1)
You have a very good point, it is in the javadocs, and in regards to precision, obviously anyone would need several landfill sites worth of justification for opting for a float for a decimal for currency, and there's additional concerns where countries like Mauritania and Madagascar are concerned ( Or at least I suspect there may be, given wikipedias