# Is this the “correct” way of distributing uneven fractions of an ETH balance?

Some friends and I built a mining rig together, each contributing different amounts of fiat to the endeavor. I'm adapting the contract from this answer to receive ETH from MiningPoolHub and distribute it to our separate addresses according to how much fiat we put into the initial cost of the rig. Have I gone about this the correct way?

``````pragma solidity ^0.4.21;
contract SplitPayment
{
address public A = 0xAAA;
uint256 public A_share  = 111111111;

address public B  = 0xBBB;
uint256 public B_share  = 222222222;

address public C = 0xCCC;
uint256 public C_share = 666666667;

function sendPayment(address person, uint256 raw_share) private
{
uint256 balance = address(this).balance;
person.transfer(balance * raw_share / 1000000000);
}
function() payable public
{
sendPayment(A, A_share);
sendPayment(B, B_share);
sendPayment(C, C_share);
}
}
``````

## 1 Answer

Try something like this:

``````pragma solidity ^0.4.21;
contract SplitPayment
{
uint constant shareSum = 1000000000;

address public A = 0xaaa...;
uint256 public A_share  = 111111111;

address public B = 0xbbb...;
uint256 public B_share  = 222222222;

address public C = 0xccc...;

function() payable public
{
uint256 balance = address(this).balance;

uint toA = (balance * A_share) / shareSum;
uint toB = (balance * B_share) / shareSum;
uint toC = balance - (toA + toB);

A.transfer(toA);

B.transfer(toB);

C.transfer(toC);

assert(address(this).balance == 0);
}
}
``````