Converting a number saved as text back to a number

I’m writing a clause where I need to calculate a percentage per month in a duration. If the output of that calculation isn’t a whole number I need to round off to two numbers after the comma and then finally use the fullnr function to output that number into its full text representation. I’m using the format-nr function to achieve that along with some conditional logic.

The issue I’m running into is that the format-nr function outputs text and fullnr only takes a number or currency as its parameter, resulting in an error.

Is there a possibility to convert it back to a number? Or would there be a better way to solve this issue?

I’ll include the code below:

CALCULATIONCLIFFVESTINGWITHOUTVESTINGAFTEREXPIRYTEXT = (i.e., @fullnr(@CALCULATIONCLIFFVESTINGWITHOUTVESTINGAFTEREXPIRYROUNDED) percent (@CALCULATIONCLIFFVESTINGWITHOUTVESTINGAFTEREXPIRYROUNDED{“%”}) per month

CALCULATIONCLIFFVESTINGWITHOUTVESTINGAFTEREXPIRY = {100 / @months-in(#vesting^vesting-period)}

@CALCULATIONCLIFFVESTINGWITHOUTVESTINGAFTEREXPIRYROUNDED = {
@if(@CALCULATIONCLIFFVESTINGWITHOUTVESTINGAFTEREXPIRY != @round(@CALCULATIONCLIFFVESTINGWITHOUTVESTINGAFTEREXPIRY),
@format-nr(@CALCULATIONCLIFFVESTINGWITHOUTVESTINGAFTEREXPIRY, 2),
@CALCULATIONCLIFFVESTINGWITHOUTVESTINGAFTEREXPIRY
)
}

There may be an easier solution to this instead of using conditional logic to check whether a number is a round number or not. In the “Locale” styling settings of a document, you can configure that on a document-wide basis, there should not be more than 2 decimals shown.

After configuring this, your code can be dramatically simplified to just using the @CALCULATIONCLIFFVESTINGWITHOUTVESTINGAFTEREXPIRY placeholder and dropping the @CALCULATIONCLIFFVESTINGWITHOUTVESTINGAFTEREXPIRYROUNDED one altogether.

Finally (and this is of course to some extent a question of personal preference), I would consider shortening the names of your placeholders to make the syntax slightly more legible, as well as less sensitive to typos when you are (or someone else is) editing the clause. :slight_smile:

That’s definitely makes things cleaner, thank you!

Fully agree on the naming of the snippets. I’ve simplified it :smiley:

1 Like