Force point (“.”) as decimal separator in java

Use the overload of String.format which lets you specify the locale: return String.format(Locale.ROOT, “%.2f”, someDouble); If you’re only formatting a number – as you are here – then using NumberFormat would probably be more appropriate. But if you need the rest of the formatting capabilities of String.format, this should work fine.

Is it possible to get 0 by subtracting two unequal floating point numbers?

In Java, a – b is never equal to 0 if a != b. This is because Java mandates IEEE 754 floating point operations which support denormalized numbers. From the spec: In particular, the Java programming language requires support of IEEE 754 denormalized floating-point numbers and gradual underflow, which make it easier to prove desirable … Read more

Swift double to string

It is not casting, it is creating a string from a value with a format. let a: Double = 1.5 let b: String = String(format: “%f”, a) print(“b: \(b)”) // b: 1.500000 With a different format: let c: String = String(format: “%.1f”, a) print(“c: \(c)”) // c: 1.5 You can also omit the format property … Read more

Why does this random value have a 25/75 distribution instead of 50/50?

Because nextDouble works like this: (source) public double nextDouble() { return (((long) next(26) << 27) + next(27)) / (double) (1L << 53); } next(x) makes x random bits. Now why does this matter? Because about half the numbers generated by the first part (before the division) are less than 1L << 52, and therefore their … Read more

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