Monday, November 18, 2024
Google search engine
HomeLanguagesJavascriptD3.js fsum() Method

D3.js fsum() Method

With the help of d3.fsum() method, we can get the  full precision sum of a floating point array values by using this method and return sum of all the values.

Syntax:

d3.fsum([values])

Parameter: This function has the following parameter as mentioned above and described below:

  • values: It is an array of values which is passed as parameter.

Return Value: It return the full precision sum of values in an array.

Note: To execute the below examples, you have to install the d3 library by using this command prompt we have to execute the following command.

npm install d3

Example 1: In this example, we can see that by using d3.fsum() method, we are able to compute the full precision sum of floating point values in an array by using this method.

Filename: index.js




// Defining d3 contrib variable  
var d3 = require('d3');
  
var gfg = d3.fsum([5.4, 4.5, 21.3, -1.9998372, 1.01])
  
console.log(gfg)


Output:

30.210162800000003

Example 2: Filename: index.js




// Defining d3 variable  
var d3 = require('d3');
  
var arr = []
for(var i = 0; i < 5; i++) {
    arr.push(i);
}
  
var gfg = d3.fsum(arr)
  
console.log(gfg)


Output:

10

Note: The above program will compile and run by using the following command:

node index.js

Reference: https://github.com/d3/d3-array/blob/master/README.md

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

RELATED ARTICLES

Most Popular

Recent Comments