BigDecimal – to use new or valueOf

Those are two separate questions: “What should I use for BigDecimal?” and “What do I do in general?” For BigDecimal: this is a bit tricky, because they don’t do the same thing. BigDecimal.valueOf(double) will use the canonical String representation of the double value passed in to instantiate the BigDecimal object. In other words: The value … Read more

Convert seconds value to hours minutes seconds?

Is it necessary to use a BigDecimal? If you don’t have to, I’d use an int or long for seconds, and it would simplify things a little bit: hours = totalSecs / 3600; minutes = (totalSecs % 3600) / 60; seconds = totalSecs % 60; timeString = String.format(“%02d:%02d:%02d”, hours, minutes, seconds); You might want to … Read more

BigDecimal setScale and round

One important point that is alluded to but not directly addressed is the difference between “precision” and “scale” and how they are used in the two statements. “precision” is the total number of significant digits in a number. “scale” is the number of digits to the right of the decimal point. The MathContext constructor only … Read more

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