scoreboard players operation @s temp = $temp main
execute if score $temp main matches 100..999 run scoreboard players operation @s temp /= $10 main
execute if score $temp main matches 1000..9999 run scoreboard players operation @s temp /= $100 main

scoreboard players operation @s temp2 = $temp main
execute if score $temp main matches 100..999 run scoreboard players operation @s temp2 %= $10 main
execute if score $temp main matches 1000..9999 run scoreboard players operation @s temp2 %= $100 main
execute if score $temp main matches 1000.. run scoreboard players add @s[scores={temp2=0..9}] temp2 800