Java – How to round double / float value to 2 decimal places
There are a few ways to round float or double to 2 decimal places in Java. In short, for monetary calculation, picks BigDecimal; for display purpose, picks DecimalFormat("0.00"). We can…
Favourite tutorials for developers
Core Java is the fundamental form of Java. We use it in all Java platforms and technologies. Without going through core Java, it is impossible to advance to advanced Java. Unlike core Java, advanced Java is a specialization of the core Java in some particular domain, such as database handling, networking, and the web.
There are a few ways to round float or double to 2 decimal places in Java. In short, for monetary calculation, picks BigDecimal; for display purpose, picks DecimalFormat("0.00"). We can…
In Java, there are few ways to display double in 2 decimal places. We can use DecimalFormat("0.00") to ensure the number is round to 2 decimal places. We also can…
There are many monetary values calculation in the financial or e-commerce application, and there is one question that arises for this – Should we use double or float data type…
In Java 8, we can use the Stream.reduce() to sum a list of BigDecimal. Java example to sum a list of BigDecimal values, using a normal for loop and a…
In Java 8 Stream, the findFirst() returns the first element from a Stream, while findAny() returns any element from a Stream.
Code snippets to convert a primitive array int to a List. In Java 8, you can use the Stream APIs to do the boxing and conversion. You can’t use the…
Java example to show the use of Arrays.sort() to sort an Array. The code should be self-explanatory. Output Download Source Code $ git clone https://github.com/favtuts/java-core-tutorials-examples $ cd java-basic/array Reference Arrays…
The methods described below are only applicable to one dimensional arrays. Arrays inherit methods from Object class, and Object.clone() is one of them. If you need to copy an Array…
In Java 8, you can either use Arrays.stream or Stream.of to convert an Array into a Stream. For object arrays, both Arrays.stream and Stream.of returns the same output. For object…
Java example to show you how to convert a Array to a List.