D3.js fsum() Method
Last Updated :
23 Sep, 2020
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
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
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
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...