|
Best of Support |
|
|
Fractional values to words |
|
Issue
There are some fields that we have set up as decimal types in our Dialogs with 1 decimal point to allow for ½ percentage points with respect to profit participation.
When these numbers come into our templates, if the number is 5.0, we will want to see 5, if it is 7.5, we will want to see 7½ and when we convert these numbers to words, we would expect to see "five" and "seven and one half" respectfully.
Right now, everything comes in as decimals, so we get "5.0", "7.5", "five" and "seven point five"
Solution:
One way of doing this is by using SetBlock to declare a "function" that will return the correctly formatted value. The following should work:
%[SetBlock("Convert")]%[x = FormatNum(Number, 1); IfTrue(Element(2, x,
'.')=5, NumberToWords(Element(1, x, '.')) & ' and one half',
NumberToWords(Number))]%[EndBlock]
Now, whenever you want to output a number, you just say:
%[Number=17.5; Convert]
You could adapt the script above to suit your exact needs. Here is some example output:
%[Number=17.0; Convert]
%[Number=17.5; Convert]
%[Number=17.7; Convert]
Seventeen
Seventeen and one half
Seventeen Point Seven
The script works by using Element() to look at the fractional part of the number when formatted to 1 decimal place. If this part is 5, then it is something "and one half".
Peter Ottermann