Dev Helpers
← Back

Split a bill without losing cents

Split a bill without losing cents using JavaScript.

Open this example in the interactive library

Source code

const cents = 1000,
  people = 3;
console.log(
  Array.from(
    { length: people },
    (_, i) => Math.floor(cents / people) + (i < cents % people ? 1 : 0),
  ),
);

Sample output

[ 334, 333, 333 ]