Suppose I have a process that receives strings like the following:
“1.542”
“1.293”
“1.652”
“1.297”
Every now and again, however, the process receives a string with fewer “decimal places”. For example:
“1.9”
I wish to create a function that takes a given string received, checks if it has less than three “decimal places”, and if so, extends the string by adding 0’s to the end to return an updated string with three decimals. For example, inputting “1.9” to the function would return “1.900”
Oooops, no, i wasn’t sugesting that. I just read the OP, started to implement two versions, and checked their peformance and thought, OP would be interested as he wrotes
I wasn’t very concentrated, sorry for making you (and probably others) puzzled.
rpad in base does virtually the same as oheil’s rpad2 - except that it can take more than 1 character as “padding” string.
The OP didn’ specify if the left side of the numbers will always have one digit. If not, the n argument to rpad should be the sum of the number of decimals and the position of the decimal point (e.g. findfirst('.', s)).