+ 1
How to divide sum into equal parts with last one being remainder(if necessary)? JAVASCRIPT
Example: var a = sum; // 479,25 var b = divider number; // 6 So that programs result would display: 79,88 79,88 79,88 79,88 79,88 79,85 It could also display: 80 80 80 80 80 79,25 Both is right, as long as the sum of divided parts is still equal to 479,25.
8 Answers
+ 1
Hi F.M.
I see you have posted 3 questions over this topic. Just curious as to why, I saw people answering your question, so, you gotta have a good reason for reposting this topic, I guess.
+ 1
Hi Ipang,
I deleted one post now. I posted them because, so far, I didnât get the solution. Do you have it?
+ 1
Well, I kinda do,
But you only have 1 test case (479.25 divided by 6)
I don't know how my idea will work when a different number is given to test.
Anyways, you got a code this far?
(Edit)
This is my idea for code
https://code.sololearn.com/W5yhd83PtLgE/?ref=app
+ 1
I donât..
Here is another example:
var a = 97.82; // total bill
var b = 4; // no. of installments
var c = a/b; /* which is 97,82/4 = 24,455 - with .toFixed(2) itâs 24,46 */
But now, the sum of 4 installments = 97.84.
So I need different way, to divide installments into 4 amounts. The amounts could also display 3 same amounts with the last one being the remainder of the total sum(97.82).
+ 1
I think, I understand the task now.
Here's an attempt (though not js), see my comments in the script.
https://code.sololearn.com/ccMFyMUw7xvf/?ref=app
0
Hi divyanshu kumar .
Your code is in the right direction.
But it shows me only one number. In this case the result shows:
11
But, what I would like show is:
9
9
11
How to do that?