Integer.valueOf() vs. Integer.parseInt() [duplicate]

Actually, valueOf uses parseInt internally. The difference is parseInt returns an int primitive while valueOf returns an Integer object. Consider from the Integer.class source: public static int parseInt(String s) throws NumberFormatException { return parseInt(s, 10); } public static Integer valueOf(String s, int radix) throws NumberFormatException { return Integer.valueOf(parseInt(s, radix)); } public static Integer valueOf(String s) … Read more

How to change the decimal separator of DecimalFormat from comma to dot/point?

You can change the separator either by setting a locale or using the DecimalFormatSymbols. If you want the grouping separator to be a point, you can use an european locale: NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN); DecimalFormat df = (DecimalFormat)nf; Alternatively you can use the DecimalFormatSymbols class to change the symbols that appear in the formatted numbers … Read more

How to print a float with 2 decimal places in Java?

You can use the printf method, like so: System.out.printf(“%.2f”, val); In short, the %.2f syntax tells Java to return your variable (val) with 2 decimal places (.2) in decimal representation of a floating-point number (f) from the start of the format specifier (%). There are other conversion characters you can use besides f: d: decimal … Read more

Formatting a number with exactly two decimals in JavaScript

To format a number using fixed-point notation, you can simply use the toFixed method: (10.8).toFixed(2); // “10.80” var num = 2.4; alert(num.toFixed(2)); // “2.40” Note that toFixed() returns a string. IMPORTANT: Note that toFixed does not round 90% of the time, it will return the rounded value, but for many cases, it doesn’t work. For … Read more

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