You can perform the following steps:

* Calculate the actual total (11,479,682,004 in your example).

* Calculate the formatted total (11,480).

* If formatted_total = (int)(actual_total / 1000000) then everything's fine. Note that int (or an equivalent function) should be used to remove the fraction part rather than round the number to the nearest integer.

* If formatted_total > (int)(actual_total / 1000000) then do the following:

* Loop through each of the added amounts, and quit the loop at the first amount found where formatted_amount > (int)(actual_amount / 1000000).

* Decrement the formatted_amount of the found item by 1.

_______________

Nayer Naguib

* Calculate the actual total (11,479,682,004 in your example).

* Calculate the formatted total (11,480).

* If formatted_total = (int)(actual_total / 1000000) then everything's fine. Note that int (or an equivalent function) should be used to remove the fraction part rather than round the number to the nearest integer.

* If formatted_total > (int)(actual_total / 1000000) then do the following:

* Loop through each of the added amounts, and quit the loop at the first amount found where formatted_amount > (int)(actual_amount / 1000000).

* Decrement the formatted_amount of the found item by 1.

_______________

Nayer Naguib