Open In App

D3.js interpolateRound() Function

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.

Return Values: It returns the Interpolator function.



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

Example 1:




<!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.




<!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:


Article Tags :