This journal is available for random discussion topics of interest to the community, with just a few rules:
1) No personal attacks, grumbling about site policy, or complaining about other users and the staff.
2) No racism, bigotry, or culture wars of any kind.
3) No politics of any kind. There are plenty of other places to discuss this topic. Policy discussion is okay, though, as long as it focuses on the issues instead of people or parties. Be sure to follow rule #2 here.
4) No random spamming. If you're an member of the site who intends to regularly contribute and participate, and you wish to discuss your personal projects, that's fine. If you're a drive-by spammer who's here just to promote your business or hosts file software, get lost.
5) Please be kind to each other.
Otherwise, you're welcome to discuss anything you'd like in this journal.
(Score: 1) by khallow on Wednesday September 04 2024, @01:09AM (3 children)
Rounding up:
2.46
2.5
3
versus rounding to nearest even digit:
2.46
2.5
2
(Score: 2, Touché) by Anonymous Coward on Wednesday September 04 2024, @02:34AM (2 children)
He is a Java programmer, so the answer is obvious. How rounding is handled depends on the version of Java in use, the input type, and the desired output type. The fact that the actual rounding mode is different for the different combinations is just one of those language behaviours you have to remember. Yet another language feature that makes it the best language ever.
(Score: 2) by DannyB on Wednesday September 04 2024, @04:08PM (1 child)
When using the BigDecimal type (in Java), you must specify the rounding mode for operations. BigDecimal internally uses a BigInteger along with an int that keeps track of how many decimal digits are to the right of the decimal point.
Never use floating point types for money.
The server will be down for replacement of vacuum tubes, belts, worn parts and lubrication of gears and bearings.
(Score: 0) by Anonymous Coward on Wednesday September 04 2024, @11:27PM
No, you don't. Most BigDecimal operations are not infinite precision, (half of those are only infinite for certain expansions) and, therefore, don't require a MathContext. If you never use one of those, then you may not even realize it. And there are multiple MathContexts that could be considered the "default" with different rounding modes. And don't get me started on DecimalFormat having a different default rounding mode or that the defaults change for various versions.