WEBLOG
Setting Max/Min Digits For Decimal Numbers With Java DecimalFormat
The DecimalFormat class offers the following four such methods which can be used to easily set the maximum and/or minimum digits for decimal numbers. As shown in the below table, two of these methods can set max/min digits for integer part while the other two methods can do the same for the fraction part of the decimal numbers as...
Rounding Decimal Number With Java DecimalFormat
The DecimalFormat class has a method called setRoundingMode() which can be used for setting the rounding mode for DecimalFormat object. The setRoundingMode() accepts RoundingMode class object as the parameter. You can pass any of the Enum constants available in the RoundingMode class as parameter to the setRoundingMode() method to achieve the desired rounding of decimal number. The following example demonstrates...
Format Decimal Numbers with Grouping Separator
The DecimalFormat class has a method called setGroupingSize() which sets how many digits of the integer part to group. Groups are separated by the grouping separator. Hence you can use setGroupingSize() method to change the default group digits number as you need. The following example demonstrates setting grouping separator for integer part of the decimal number: 219bd6a59d7bd881631c58a62a5ed178 The above code produces the...
Java DecimalFormat Class
When you need to format decimal numbers, such as taking three or two decimal places for a number, showing only the integer part of a number, etc. such scenarios can be tackled with java.text.DecimalFormatclass, which can help you to format numbers using your specified pattern. The java.text.DecimalFormat class is used to format numbers using a user specified formatting. This concrete...
Format Decimal Numbers using Strings Within Pattern
As mentioned in earlier posts, the java.text.DecimalFormat class is used to format decimal numbers via predefined patterns specified as String. Apart from the decimal separator, grouping separator, currency separator etc., It is also possible to mix String literals within the pattern. The following example demonstrates embedding String literals within pattern: b8c17d2e8b2af4b43df92c35de7031e8 The above code produces the following output: My formatted number is 170,180.246
Format Decimal Numbers Using Format Symbols
You can customize which symbols are used as decimal separator, grouping separator, currency seperator etc. using a DecimalFormatSymbols instance together with java.text.DecimalFormat class. The DecimalFormatSymbols instance can be passed to java.text.DecimalFormat constructor followed by the call to format() method of java.text.DecimalFormat to achieve the desired decimal separator, grouping separator character etc. The following example demonstrates formatting using DecimalFormatSymbols: 6a0a52cac039f0020809ed8feb43ddb9 The...
HomeWeblog
FT AUTOMATION
Introducing Testing-as-a-Service (TaaS)
The 'Cloud Computing' technology has revolutionized the IT industry and it has something good to offer to...
HOW-TO'S
How To Change Font for Eclipse Package Explorer
This article shows how to change the Package Explorer text size and style. The font used for tree...
NFT AUTOMATION
How To Do API Testing with JMeter
Introduction Application Programming Interface is a very popular term among developers. It is simply a request provider that...
PROGRAMMING
Convert List to Array Using ToArray With Param
There is an overloaded version of the toArray method. This accepts an array as a parameter and returns a...
Remove Duplicates from List Using Set.addAll
The Set interface has a method called addAll. This accepts a 'Collection' as the parameter. So if you invoke this method by passing the 'List', the duplicates will be eliminated. The following code snippet demonstrates this method. Here, a new LinkedHashSet is created and the addAll method is invoked by passing the List as input. So this will automatically create...
How To Remove Duplicates From List in Java
Introduction A List is an interface in the Java collection framework which can be used to store a group of objects. A List is ordered and it allows duplicates. However, there are often scenarios where you would need to eliminate duplicate elements from a List. There are several ways you can achieve this. In the next few sections, I will be...
Convert List to Array Using ToArray Without Param
Java provides a toArray method on the 'List' interface. This can be used to convert a 'List' to an array. Since there are are two overloaded versions, one of these method is explained below. This toArray method does not accept any input parameters. It returns an object array. The following code snippet demonstrates this approach. Here, the toArray method is...
Getting Started with Selenium WebDriver
Table of Contents 1. Selenium and Selenium Web Driver 2. Setting-Up the Environment 3. Test Script with Selenium Web Driver 3.1) Creating a project 3.2) Creating a Class 4. Code a Simple Selenium Script 5. Running the test Testing is a critical step in the Software Development Life Cycle. Software testing helps to ensure the quality and effectiveness of the final product. Automated...
Remove Duplicates from List Using LinkedHashSet
Another implementation of the Set interface is LinkedHashSet. LinkedHashSet maintains the order of elements and helps to overcome the HashSet limitation. The following code demonstrates this: This code is quite similar to the one seen earlier, except that it uses a LinkedHashSet. The input List is passed as a parameter to the LinkedHashSet constructor. d5e45fc48b7575762bc7c187109c7ad1 Since a LinkedHasSet is used, the...
Java Tutorial #1 – Variables and Data Types
Table of Contents Introduction 1. Variables 2. Data Types Primitive Data Types Integer Data Types Decimal Data Types Character Data Types Boolean Data Types Reference Data Types Introduction Variables are names that are used to identify memory locations that store values. Each variable belongs to a particular data type. Data types determine the size of the memory location.In this article, we will...
Convert List to Array Using Stream with Param
There is an overloaded version of the Stream.toArray method which can be used to return a result array that is of the same data type as the input array. The following code demonstrates this: Firstly, the 'stream()' method is invoked on the input List which returns a Stream corresponding to the List. Then the overloaded 'toArray' method is invoked. This...
CODE SNIPPETS | CODEX
How-To Linux
How To Change Your Default Linux Shell
The shell is a program that accepts and interprets commands. Besides bash, Linux supports many other shell programs,...
How-To Git
How To Install Pacman For Git on Windows
The 'Git for Windows' by default does not come with MSYS2 package manager called 'Pacman' and hence it...
Git
Common Git Commands Reference
Git is the most popular distributed version control system which is currently an actively maintained open-source project. Git...
ÂÂ



