You can use ROUND() function.The syntax is as followsSELECT ROUND(yourColumnName, yourPrecisionIntegerValue) from yourTableName;To understand the concept, let us create a table. The query to create a table is as followsmysql> create table givenPrecisionDemo -> ( -> Amount float -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into givenPrecisionDemo(Amount) values(45.678); Query OK, 1 row affected (0.12 sec) mysql> insert into givenPrecisionDemo(Amount) values(123.456); Query OK, 1 row affected (0.15 sec) mysql> insert into givenPrecisionDemo(Amount) values(245.890); Query OK, ... Read More
The forEach() method of the DoubleStream class performs an action for each element of this stream.The syntax is as follows:void forEach(DoubleConsumer action)Here, DoubleConsumer represents an operation that accepts a single double-valued argument and returns no result. The parameter action is a non-interfering action to perform on the elements.To use the DoubleStream class in Java, import the following package:import java.util.stream.DoubleStream;Create a DoubleStream and add some elements to the stream:DoubleStream doubleStream = DoubleStream.of(45.7, 67.8, 89.7, 95.6);Now, display the elements:doubleStream.forEach(System.out::println);The following is an example to implement DoubleStream forEach() method in Java:Example Live Demoimport java.util.stream.DoubleStream; public class Demo { public static void main(String[] args){ ... Read More
In this section we are going to see the type of image file we have. So consider a situation, where in a directory we have hundreds of image file and we want to get all the jgeg(or any particular image file type) file type. All this we are going to do programmatically using python.Python provide library to determine the type of an image, on such library is imghdr.The python imghdr package determines the type of image contained in a file or byte stream.InstallationThere is a very much chances that if you are using python 3.6 or higher, imghdr module is ... Read More
You need to use $exists operator to determine whether a field exists in MongoDB. Let us first create a collection with documents> db.determineFieldExistsDemo.insertOne({"ClientName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9eb245d628fa4220163b75") } > db.determineFieldExistsDemo.insertOne({"ClientName":"Larry", "ClientAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5c9eb25cd628fa4220163b76") } > db.determineFieldExistsDemo.insertOne({"ClientName":"Mike", "ClientCountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9eb26fd628fa4220163b77") } > db.determineFieldExistsDemo.insertOne({"ClientName":"Sam", "ClientAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5c9eb286d628fa4220163b78") }Following is the query to display all documents from a collection with the help of find() method> db.determineFieldExistsDemo.find().pretty();This will produce the following output{ "_id" : ObjectId("5c9eb245d628fa4220163b75"), "ClientName" : "John" ... Read More
You can use DEFAULT command for this. Following is the syntax −alter table yourTableName change yourColumnName yourColumnName TINYINT(1) DEFAULT 1 NOT NULL;Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(20), UserAge int, isMarried tinyint(1) ); Query OK, 0 rows affected (0.80 sec)Let us check the description of table −mysql> desc DemoTable;This will produce the following output −+-----------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+-------------+------+-----+---------+----------------+ | Id ... Read More
A temporary file can be created using the method java.io.File.createTempFile(). This method requires two parameters i.e. the prefix to define the file name and the suffix to define the file extension. It also returns the abstract path name for the temporary file created.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo { public static void main(String[] args) throws Exception { File file = File.createTempFile("temp", null); System.out.println(file.getAbsolutePath()); file.deleteOnExit(); } }The output of the above program is as follows −OutputC:\Users\amit_\AppData\Local\Temp\temp6072597842246154962.tmpNow let us understand the above ... Read More
A char array for the buffer can be obtained using the method array() in the class java.nio.CharBuffer. If the returned array is modified, then the contents of the buffer are also similarly modified and vice versa. If the buffer is read-only, then the ReadOnlyBufferException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { CharBuffer buffer = CharBuffer.allocate(n); buffer.put('A'); buffer.put('P'); ... Read More
In C++ we can overload some operators like +, -, [], -> etc. But we cannot overload any operators in it. Some of the operators cannot be overloaded. These operators are like below? “.” Member access or dot operator? “? : ” Ternary or conditional operator? “::” Scope resolution operator? “.*” Pointer to member operator? “sizeof” The object size operator? “typeid” Object type operatorThese operators cannot be overloaded because if we overload them it will make serious programming issues.For an example the sizeof operator returns the size of the object or datatype as an operand. This is evaluated by the ... Read More
To remove array element by its index in MongoDB, you can use $unset and $pull operator. There are two steps to remove array elements from an array.The syntax for the same is as follows:db.yourCollectionName.update({}, {$unset:{"yourArrayListName.yourPosition":yourPositionValue}}; db.yourCollectionName.update({}, {$pull:{"yourArrayListName":null}});To understand the above syntax, let us create a collection with document. The query to create a collection with document is as follows:>db.removeArrayElements.insertOne({"StudentName":"Larry", "StudentAge":23, "TechnicalSub ject":["C", "C++", "Java", "MongoDB"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c6ea4879c4643706aef56d2") }Display all documents from a collection with the help of find() method. The query is as follows:> db.removeArrayElements.find().pretty();The following is the output:{ "_id" : ObjectId("5c6ea4879c4643706aef56d2"), ... Read More
Here is a summary of important methods available through the session object −Sr.No.Method & Description1public Object getAttribute(String name)This method returns the object bound with the specified name in this session, or null if no object is bound under the name.2public Enumeration getAttributeNames()This method returns an Enumeration of String objects containing the names of all the objects bound to this session.3public long getCreationTime()This method returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.4public String getId()This method returns a string containing the unique identifier assigned to this session.5public long getLastAccessedTime()This method returns the last ... Read More