Open In App

D3.js interpolateRound() Function

Last Updated : 28 Jul, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The d3.InterpolateRound() Function is used to return the interpolate of two given numbers and round them to the nearest integer.

Syntax:

d3.interpolateRound(a,b)

Parameters: This function accepts two parameters as mentioned above and describe below.

  • a: It is any number.
  • b: It is any number.

Return Values: It returns the Interpolator function.

Below given are a few Examples of Interpolate.Round() function.

Example 1:

HTML




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0">
  <title>D3.js d3.interpolateRound() Function</title>
</head>
<style>
</style>
<body>
  <!--Fetching from CDN of D3.js -->
  <script type = "text/javascript" src
  </script>
  <script>
    console.log("Type is: ",typeof(d3.interpolateRound(4,5)))
    console.log(d3.interpolateRound(-2636,586)(0.2))
    console.log(d3.interpolateRound(3545,96.485)(0.6))
    console.log(d3.interpolateRound(24.1545,458)(0.2))
  </script>
</body>
</html>


Output:

Example 2: When pass anything other than number.

HTML




<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" 
        content="width=device-width, initial-scale=1.0">
  <title>D3.js d3.interpolateRound() Function</title>
</head>
<style>
</style>
<body>
  <!--Fetching from CDN of D3.js -->
  <script type = "text/javascript" src
  </script>
  <script>
    console.log("Type is: ",typeof(d3.interpolateRound(4,5)))
    console.log(d3.interpolateRound([1,2,3],[2,3,4])(0.2))
    console.log(d3.interpolateRound(3545,"green")(0.6))
    console.log(d3.interpolateRound("green","red")(0.2))
    console.log(d3.interpolateRound(245889,)(0.2))
  </script>
</body>
</html>


Output:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads