How do you determine how many people would have to receive extra pennies in a room

Asked

Viewed 56 times

-1

Good evening, folks, the story and the following: a command of value of 100 real, divided by 3 people would be 33.33333, using toFixed(2) and returns 33,33(and one of the objectives), but when you do the sum of these values to confirm is in this example missing 1 cent.

how could I do to determine how many people would have to receive the extra pennies for the account to close. Ex1: value of 100/3 = cliente1: 33.34, cliente2: 33.33 and cliente3: 33,00 Ex2: value of 100/7 = each customer would be with 14.28 and adding this value is 99.96 (where the 4 cents went)

Note: I have already researched, in fact. I did not get an answer to the problem

  • 2

    that cheap people claimed 1 cent credo... leaves to the waiter! D

  • people will not receive the pennies that are left over equally (that is if it is not only 1 cent), because it does not play everything for a single customer?

  • So Father, I thought about this solution too, but depending on the value and quantity of the divisor, this value of 1 cent can vary.

  • To close account, someone will have to pay these extra cents, will never be totally "fair". In case you have 4 cents left, you decide if you can give one to pay everything or if you give one penny to 4 "lucky" (that is, 6 people pay 14.28 and one pays 14.32, or 3 pay 14.28 and 4 pay 14.29), or any other criteria you want (1 pays 1 cent and another pays 3, or 2 people pay 2 cents more, I don’t know, you have to choose a criterion of distribution of the cents that are left)

  • Add a penny to one of the 3 and you’re done.

2 answers

0

See if I understand the problem:

You have an amount X that will be divided between 3 participants.

You need to divide equally between the 3 participants the X/3 toFixed(2) multiplied by three.

If that’s it, you take 100, subtract by what’s left, and then take the result, divide by three 3, which will give a Z amount (broken). Then you give a Z value to each of the three people.

How to divide 1 cent between three people? Simple: Divide by three and give 0.003333333333333 for each of them.

0

Makes whole.

  1. Multiply the value of the account by 100. In your example, that the account is 100.00, would be 10000. Remember to use the value as integer after multiplying by 100.

  2. Takes the value of divisão inteira of account value by number of customers. In your example (10000 DIV 3), the result will be 3333.

  3. Take the rest of the whole division. In your example (10000 MOD 3) will be 1. This rest is the amount of people who will have to pay a penny more than the others. Suppose this value is in the variable RESTO.

  4. Choose the RESTO people who will pay extra and add 1 to each of them. In your example, one person will be 3334 and the other 2 will be 3333.

  5. Divide the value of each of them by 100. In your example: 33:33, 33:33 and 33:34.

If you look at the second example: 100 real for 7 people:

100 * 100   => 10000
10000 DIV 7 => 1428.... um vetor: [1428, 1428, 1428, 1428, 1428, 1428, 1428]
10000 MOD 7 => 4 ... escolha 4 sortudos pra pagar 1 centavo a mais que os outros

Supondo que você decidiu escolher os primeiros da fila:
[1429, 1429, 1429, 1429, 1428, 1428, 1428]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.