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

17th Apr 2021, 1:09 PM
F.M.
6 Antworten
+ 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.
17th Apr 2021, 2:24 PM
Ipang
+ 1
Hi Ipang, I deleted one post now. I posted them because, so far, I didn’t get the solution. Do you have it?
17th Apr 2021, 2:29 PM
F.M.
+ 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
17th Apr 2021, 2:32 PM
Ipang
+ 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).
17th Apr 2021, 2:54 PM
F.M.
+ 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
17th Apr 2021, 3:43 PM
Lisa
Lisa - avatar
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?
19th Apr 2021, 12:58 PM
F.M.