Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 362

# FM - Percent to Text Custom Function Off

Below is a PercenttoText custom function that I believe I adapted from a CurrencytoText function.  However, it does not display correctly when the 100ths digit is 0 as follows.  Notice it says 7/100 instead of 70/100.  I thought I found the problem but was wrong.  See formula below.  Thanks for your help; I know this is easy for many of you, but I get lost in too much detail.

The Tenant agrees to pay an amount equal to Nine and 7/100 (9.7%) percent of the cost of snow and ice removal.

If ( FIELD = 0; "" ;

Choose ( Int ( Mod ( FIELD;10^3 ) / 100 ) ; ""; "One Hundred "; "Two
Hundred "; "Three Hundred "; "Four Hundred "; "Five Hundred "; "Six
Hundred "; "Seven Hundred "; "Eight Hundred "; "Nine Hundred " )

& Case ( Int ( Mod ( FIELD;10^3 ) / 100 ) > 0 and Int ( FIELD / 10 ) > 0; "and " ; "" )

&

If ( Int ( Mod ( FIELD;100 ) / 10 ) = 1 ;

Choose ( Int ( Mod ( FIELD;10 ) ) ; "Ten"; "Eleven"; "Twelve";
"Thirteen"; "Fourteen"; "Fifteen"; "Sixteen"; "Seventeen";
"Eighteen"; "Nineteen" ) ;
Choose ( Int ( Mod ( FIELD;100 ) / 10 ) ; "" ; "" ; "Twenty"; "Thirty";
"Forty"; "Fifty"; "Sixty"; "Seventy"; "Eighty"; "Ninety" ) &
If ( Int ( Mod ( FIELD;100 ) / 10 ) > 0 ;  "-" ; "" ) &
Choose ( Int ( Mod ( FIELD;10 ) ) ; ""; "One"; "Two"; "Three"; "Four"; "Five"; "Six"; "Seven"; "Eight"; "Nine" ) )

&

If ( Mod ( FIELD; 1 ) and Int ( FIELD ) ;" and ";"" )

&

Case ( Mod ( Int ( FIELD*10 ) ; 10 ) = 1;
Choose ( Mod ( Int ( FIELD*100 ) ; 10 ) ; "10"; "11"; "12";
"13"; "14"; "15"; "16"; "17"; "18"; "19" ) ;
Mod ( Int ( FIELD*10 ) ; 10 )  >  1 ;
Choose ( Mod ( Int ( FIELD*10 ) ; 10 ) ; ""; ""; "2"; "3";
"4"; "5"; "6"; "7"; "8"; "9" )
&
Choose ( Mod ( Int ( FIELD*100 ) ; 10 ) ; ""; "1"; "2"; "3";
"4"; "5"; "6"; "7"; "8"; "9" ) ;
Mod ( Int ( FIELD*10 ) ; 10 )  < 1 ;
Choose ( Mod ( Int ( FIELD*10 ) ; 10 ) ; ""; ""; "2"; "3";
"4"; "5"; "6"; "7"; "8"; "9" )
& If ( Int ( Mod ( FIELD;100 ) / 100 ) > 0 ;  "0" ; "" ) &
Choose ( Mod ( Int ( FIELD*100 ) ; 10 ) ; ""; "1"; "2"; "3";
"4"; "5"; "6"; "7"; "8"; "9" ) ;

)

&

Case ( Mod ( FIELD; 1 )  >  0; "/100 (" & FIELD & "%)" ; Mod ( FIELD; 1 ) = 0; " (" & FIELD & "%)" ; "" )
& " percent"

)
0
rvfowler2
• 2
• 2
1 Solution

PresidentCommented:
The function isn't particularly efficient on the fraction part. I would probably take the last section that deals with the fraction with something like this:

Right( "00" & Mod( Int( Start amount *100 ) ; 100 ) ; 2 )

This tests out correctly.
Decimal-Test.fmp12
0

Author Commented:
Worked perfectly, thanks.  You're right. very inefficient.  will have to look at the rest of it because it uses the same format.
0

PresidentCommented:
Actually, the translation to text section is probably OK because the words are unique and not easily calculable the way numbers are. You could take out the "hundred" from each choice in the first section and add it at the end to shorten it up, but that's all I can see right now.
0

Author Commented:
Yes, I see what you mean.
0

## Featured Post

• 2
• 2
Tackle projects and never again get stuck behind a technical roadblock.