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

How to pad a string with leading zeros in Python 3 [duplicate]

Make use of the zfill() helper method to left-pad any string, integer or float with zeros; it’s valid for both Python 2.x and Python 3.x. It important to note that Python 2 is no longer supported. Sample usage: print(str(1).zfill(3)) # Expected output: 001 Description: When applied to a value, zfill() returns a value left-padded with … 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

Rounding error in Python with non-odd number? [duplicate]

Python 3.x, in contrast to Python 2.x, uses Banker’s rounding for the round() function. This is the documented behaviour: [I]f two multiples are equally close, rounding is done toward the even choice (so, for example, both round(0.5) and round(-0.5) are 0, and round(1.5) is 2). Since floating point numbers by their very nature are only … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)