Is inconsistency in rounding between Java 7 and Java 8 a bug?

It looks like this was a long-standing bug in JDK 7 that was finally fixed. See for example: https://bugs.openjdk.java.net/browse/JDK-8029896 https://bugs.openjdk.java.net/browse/JDK-7131459 There is a draft plan to provide the following advisory with JDK 8 which explains the issue: ——————————————————————— Area: Core Libraries / java.text Synopsis: A wrong rounding behavior of JDK7 has been fixed. The rounding … Read more

Rounding down to 2 decimal places in c#

The Math.Round(…) function has an Enum to tell it what rounding strategy to use. Unfortunately the two defined won’t exactly fit your situation. The two Midpoint Rounding modes are: AwayFromZero – When a number is halfway between two others, it is rounded toward the nearest number that is away from zero. (Aka, round up) ToEven … Read more

Make a button round

JDC Tech Tips: August 26, 1999: Creating Round Swing Buttons import java.awt.*; import java.awt.geom.*; import javax.swing.*; public class RoundButton extends JButton { public RoundButton(String label) { super(label); // These statements enlarge the button so that it // becomes a circle rather than an oval. Dimension size = getPreferredSize(); size.width = size.height = Math.max(size.width, size.height); setPreferredSize(size); … Read more