Sometimes, we may need to round off time or duration, on quarterly basis. The below table explains it better: Actual timeQuarterly rounded00:1200:1501:0701:0002:2502:3000:5201:0000:0400:00 To round the time or duration quarterly, you…
Format a number to 2 decimal places without rounding off | JavaScript | Example
Here you'll learn how you can format a number to 2 decimal places without rounding it off. By default, the toFixed() method would round off the number to the specified…
Format a number to 2 decimal places in JavaScript | Example
In JavaScript, you can use the toFixed() method to specify the number of digits you want after the decimal place. So, you can simply pass in 2 to toFixed() lead…
Add zero padding to numbers in JavaScript | Example
Sometimes you'd want to fill in digits with zeroes instead of nothing when showing time or something similar. For instance, you'd probably want to show 12:05 instead of 12:5 for…
Display a list of objects with unique keys in React.js | Example
It is important to append unique keys when rendering a list of objects in React.js. That way, React would know ahead of time whether or not to update a particular…
Convert string to number in JavaScript | 5 ways | Example
Earlier we've seen 6 ways to convert a number to a string in JavaScript. Now, let's have a look at how you can convert a string to a number in…
Convert number to string in JavaScript | 6 ways | Example
JavaScript is a dynamic and flexible, non strongly-typed language. While it opens a few doors for erroneous coding patterns, it also comes with several advantages. One of those is the…
Access string constants globally in Vue.js | Example
It's always a good idea to keep all your strings in one file and access them across your templates and js/ts files. You can of course use the data() method…
Replace a word/substring in a string in JavaScript | Example
You can replace any word or characters you want in JavaScript using the replace() method. One of the powerful features of the replace method is that not only can it…