private int GetCurrentPercentUL() { var maxItem = 100153UL; var currentItem = 100150UL; return (int)(currentItem / (maxItem / 100M)); } private int GetCurrentPercentBI() { var maxItem = new BigInteger(100153); var currentItem = new BigInteger(100150); return (int)(currentItem / (maxItem / 100)); } There was a variant with ulong and decimal (100M), it worked quite correctly. Then I had to increase the numerical range to BigInteger, and there was a problem with the calculation of interest. How to correctly and beautifully alter the GetCurrentPercentBI method to work correctly?
Upd:
private int GetCurrentPercentBI() { var maxItem = new BigInteger(100153); var currentItem = new BigInteger(100150); var percent = (int)(currentItem / (maxItem / new BigInteger(100))); if (percent == 100 && maxItem > currentItem) percent = 99; return percent; } There is such a solution, but for me it is ugly. If there are more correct options - write in the answers.
BigInteger(100)), and then cast the result to int. - nick_n_acurrentItem * 100 / maxItem- PetSerAl