This function takes in a bigint amount and returns a formatted string with commas separating thousands places. It declares variables to hold pieces of the amount as it loops through substringing 3 characters at a time, adding commas as thousands separators. If the last group of characters is less than 3, it handles adding that portion before the formatted thousands places string.