Hi, need some help trying to figure out a logic to do rounding. So what I would have would be 6 variables with whatever amount.
Divide each variable by 1000
Use math floor on all of them
Calculate the difference between the total before rounding and after
The remaining total (rounded to nearest whole) will then be distributed to the variables with the highest decimal
The main issue for me is after getting the decimals, sorting them by largest to smallest and then adding 1 value to each in descending order until the total difference reaches 0.
Visual Representation (No actual table to read, just showing how it would look like):
If we handle these variables as Decimal, D is needed because it means Decimal type literal.
If we handle these variable as Double, it’s ok just numeric without any alphabet.
Thanks for the help, is there a way to know which items were rounded? I want to write each element in the array using write cell and also highlight the items that had the value added to it.
Yeah, I will try to think of a logic so that the bot can refer to arrDiff and maybe do a check on the indexes of arrResult vs arrDiff. If the element in arrDiff at that specific index = 1, then it can highlight the cell.
Also, I was looking through the algorithm in debug mode and realized its not very accurate.
Ex:
Bot:
In the bot working above, you can see that it adds 3 numbers instead of 2. The remaining difference between the original - rounded = 2.37 which would then use standard round function to get 2.