Found 10483 Articles for Web Development

How can I round down a number in JavaScript?

Shubham Vora
Updated on 14-Jul-2022 12:06:17

1K+ Views

This tutorial teaches us to round down a number in JavaScript. The meaning of the round-down number is “returning the integer which is equal to or less than the current float number”.For example, if we round down the number 9.99, we get 9 as an output, and in the same way, for 8.01 we get 8 as an output. In simple terms, if you represent your current number in the number line, you must return the nearest integer that resides on the left side of the current number.In this tutorial, we will take a look at three different approaches to ... Read More

How to format a number with two decimals in JavaScript?

Kumar Ishan
Updated on 31-Oct-2023 13:02:35

102K+ Views

This tutorial will teach us how to format a number with two decimals using JavaScript. Formatting a number means rounding the number up to a specified decimal place. In JavaScript, we can apply many methods to perform the formatting. Some of them are listed as follows − The toFixed() Method Math.round() Method Math.floor() Method Math.ceil() Method The toFixed() Method The toFixed() method formats a number with a specific number of digits to the right of the decimal. it returns a string representation of the number that does not use exponential notation and has the exact number of digits after ... Read More

How to perform integer division and get the remainder in JavaScript?

Shubham Vora
Updated on 14-Sep-2022 13:38:18

2K+ Views

In this tutorial, we will learn how to perform integer division and get the remainder in JavaScript. The division operator (/) returns the quotient of its operands, where the dividend is on the left, and the divisor is on the right. When another splits one operand, the remainder operator (%) returns the residual. It always takes the dividend sign. In the operation x% y, x is known as the dividend, and y is known as the divisor. If one of the operands is NaN, x is Infinity, or y is 0, the operation returns NaN. Otherwise, the dividend x is ... Read More

How do I get the number of days between two dates in JavaScript?

Shubham Vora
Updated on 23-Sep-2024 14:08:33

9K+ Views

To get the number of days between two dates in JavaScript, we will be understanding four different approaches with stepwise explaination and example codes. In this article, we are having two different dates and our task is to get the number of days between two dates in JavaScript. Approaches to Get the Number of Days Between Two Dates Here is a list of approaches to get the number of days between two dates in JavaScript which we will be discussing in this article with stepwise explaination and complete example codes. Get Number of Days Using ... Read More

What is the maximum size of a web browser's cookies value?

Daniol Thomas
Updated on 16-Jun-2020 12:04:38

5K+ Views

The following are the details of the maximum size of web browser’s cookies value −Web BrowserMaximum cookiesMaximum size per cookieGoogle Chrome1804096 bytesFirefox1504097 bytesOpera1804096 bytesAndroid504096 bytes

How to calculate the difference between two dates in JavaScript?

Jennifer Nicholas
Updated on 17-Jun-2020 06:27:09

2K+ Views

To get dates in JavaScript, use the getTime() method. Forgetting the difference between two dates, calculate the difference between date and time.ExampleYou can try to run the following code to learn how to calculate a difference between two dates −Live Demo                    var dateFirst = new Date("11/25/2017");          var dateSecond = new Date("11/28/2017");          // time difference          var timeDiff = Math.abs(dateSecond.getTime() - dateFirst.getTime());          // days difference          var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));          // difference          alert(diffDays);          

What is the shortest function of reading a cookie by name in JavaScript?

Rishi Rathor
Updated on 16-Jun-2020 12:11:58

145 Views

Here’s the best way to read cookies by name in JavaScript. The following is the function −function ReadCookie() {    var allcookies = document.cookie;    document.write ("All Cookies : " + allcookies );    // Get all the cookies pairs in an array    cookiearray = allcookies.split(';');    // Now take key value pair out of this array    for(var i = 0; i < cookiearray.length; i++) {       name = cookiearray[i].split('=')[0];       value = cookiearray[i].split('=')[1];       document.write ("Key is : " + name + " and Value is : " + value);    } }

How to set horizontal header for a table?

Lokesh Badavath
Updated on 18-Oct-2022 10:48:06

3K+ Views

Tables in HTML can have horizontal header and vertical header. For the horizontal header, we need to set all inside a single  tag. Syntax Following is the syntax to set horizontal header for a table − horizontal header1… horizontal header2… Example 1 Now let us see an example program to set horizontal header for a table. DOCTYPE html> table, tr, th, ... Read More

How to generate random numbers between two numbers in JavaScript?

Kumar Ishan
Updated on 05-Sep-2022 07:19:27

12K+ Views

To generate a random number, we use the Math.random() function. This method returns a floating-point number in the range 0 (inclusive) to 1 (exclusive). To generate random numbers in different range, we should define the minimum and maximum limits of the range. Please follow the second syntax below for this. To generate random integers, you can follow the third and fourth syntax discussed below. As the Math.random() method gives us a random floating point number so to convert the result into an integer, we need to apply some basic math. Please follow the below syntaxes. Syntax Following is the syntax ... Read More

How to get time in milliseconds since the Unix epoch in JavaScript?

Krantik Chavan
Updated on 24-Sep-2019 08:30:59

1K+ Views

The standard Unix epoch is an expression in seconds. The Unix epoch or Unix time is the number of seconds elapsed since January 1, 1970.The getTime() method is used to return the millisecond representation of the Date object.To get time in milliseconds, use the following:var milliseconds = (new Date).getTime();

Advertisements