How can I implement a round rule at cart in custom script?

We want to have the round rule as below at Custom Script.

Would you please advise how to implement it?

At first round turn, we want to apply “round” at 2nd last digit. At second round turn, we want to apply “round” at the last digit.

Would you please advise where to implement them and how?

List Price

First Round Rule

25%Discount at 2nd most position in red.

Second Round Rule

10 % discount round at the last 1 position

Round at 2nd last digit

Round at the last digit

Item A

65,000

48,800 (48,750)

43,920

Item B

75,000

56,300 (56,300)

50690 (50688)

Total

140,000

105,100 (105,100)

94,590