Rounding Variables (Currency Values)

Questions, comments, and suggestions related to Typeitin.
Post Reply
Posts: 4
Joined: Sun Jun 20, 2021 3:06 am

Rounding Variables (Currency Values)

Post by Torano » Wed Nov 03, 2021 2:56 am

So I'm working on a button that adds two monetary amounts, then multiplies it by a percentage. However, I come across two intermittent issues: One, an extra digit in the thousandth place, or a digit missing (0) in the hundredth place. Is there a simple (or simple-ish) way to check and correct the variable so it rounds properly?

Site Admin
Posts: 91
Joined: Wed Jan 16, 2019 4:32 pm

Re: Rounding Variables (Currency Values)

Post by Wavget » Wed Nov 03, 2021 2:54 pm

Not sure this is simple-ish, but here is a solution.

{Var1=12.34} //store the result into Variable #1
{Length 2,{Var1}} //get the length of the number and store it into variable #2
{If (Var2=4) [{Var1}0]} //if the length is 4 the number is missing a zero. type the number and type an extra zero
{If (Var2=5) [{Var1}]} //if the length is 5 the number is correct, just type it
{If (Var2=6) [{Copy 1,5,3,{Var1}}{var3}]} //if the length is 6, copy the first 5 characters from variable #1 into variable #3 and then type it.

Some kind of format function would help here. I'm adding it to the TO DO list.

Post Reply