You can use Math.round()
when you sum up the array elements. This will always give the sum up to 100
function sum(number){
var percentage = 100 / number;
var somaPercentual = new Array();
for (i = 0; i <number; i ++) {
somaPercentual.push(percentage);
}
console.log(somaPercentual);
var sum = 0;
somaPercentual.forEach(item => sum+=item);
console.log(Math.round(sum));
}
sum(3);
sum(4);
sum(5);
sum(6);
So when you divide the 100 by any odd number. if it not exactly divisible then it is stored as 64 bit floating number so the value will be not exact which will when you add not give you exact 100. but in case if you divide it by a number which divide exactly like 4.234 so when you add it it will give you 100.
I have a single page html code with 3 different Tabs in that.I have a requirement of chaining the URL for each tab. I have seen some resources for changing the browser history using windows.history....
I have a single page html code with 3 different Tabs in that.I have a requirement of chaining the URL for each tab. I have seen some resources for changing the browser history using windows.history....
I try get data from my API server with axios but i get this error: 'v-bind' directives require an attribute value. I dont know how i must use v-bind to fix it. Here is my code : <template> &...
I try get data from my API server with axios but i get this error: 'v-bind' directives require an attribute value. I dont know how i must use v-bind to fix it. Here is my code : <template> &...
how to remove this jquery dialog and show it as a simple html form at the bottom of web page when clicked on button. I've a bootstrap table when i click on the add new record button it shows dialog ...
how to remove this jquery dialog and show it as a simple html form at the bottom of web page when clicked on button. I've a bootstrap table when i click on the add new record button it shows dialog ...
I'm confused by this line in my project: This id: categories-product belong to <select> and I've seen in project someone wrote this: And I'm wondering what this basically means ? $('#...
I'm confused by this line in my project: This id: categories-product belong to <select> and I've seen in project someone wrote this: And I'm wondering what this basically means ? $('#...