Forum Discussion
UrsulaLl
6 years agoQrew Assistant Captain
The cents can be done the same way, with the formula only reading up to the tenths place instead of up to millions. In my case, I needed only the digits to display in the following matter: xxx and 12/100 dollars. Therefore, I only had to grab the two digits and verify it didn't attempt to round them etc.
var number Split = Frac([xxTHENUMERICFIELDxx]);
ToNumber(Left(Right(ToText($Split)&"0","."),2))
This formula reliably grabs the single or double digit after the decimal point, and keeps them exactly as is. I am adding a calculation that also adds a 0 after a digit to protect against user error. Ex. $100.2 should behave like $100.20. By adding a 0 after every number that is grabbed, I can confidently pull back a two digit number. whew. The final formula just adds [formula field 1] & "." & [formula field 2].
I am at Empower, so if anyone wants to chat, find me on the app!
var number Split = Frac([xxTHENUMERICFIELDxx]);
ToNumber(Left(Right(ToText($Split)&"0","."),2))
This formula reliably grabs the single or double digit after the decimal point, and keeps them exactly as is. I am adding a calculation that also adds a 0 after a digit to protect against user error. Ex. $100.2 should behave like $100.20. By adding a 0 after every number that is grabbed, I can confidently pull back a two digit number. whew. The final formula just adds [formula field 1] & "." & [formula field 2].
I am at Empower, so if anyone wants to chat, find me on the app!
JimHarrison
5 years agoQrew Champion
I am so appreciative I didn't have to do this!
a few changes.
removed dashes between values, added "Dollar"/"Dollars" and cents at the end. Below is all three fields needed with their names underlined. Look for [<currency field>] and replace it with the field in your table.
_____________[currencyToWords] type text/rich text formula
var number OriginalValue = [<currency field>];
var number Value = Round($OriginalValue,0.01);
var text Hundreds=Right(ToText(Int($Value)),3);
var text Thousands = If($Value>=1000,ToText(Int($Value/1000)));
var text Millions = If($Value>=1000000,ToText(Int($Value/1000000)));
var text numt = ToText(Floor($OriginalValue));
var text firstNum = Case(Floor(ToNumber(Right($numt,2))/10),
1, "Ten", 2, "Twenty", 3, "Thirty", 4, "Forty", 5, "Fifty", 6, "Sixty", 7, "Seventy", 8, "Eighty", 9, "Ninety", 0, "");
var text secondNum = Case(ToNumber(Right($numt,1)),
1, "One", 2, "Two", 3, "Three", 4, "Four", 5, "Five", 6, "Six", 7, "Seven", 8, "Eight", 9, "Nine", 0, "");
var text thirdNum = Case(Floor(ToNumber(Right($numt,3))/100),
1, "One Hundred", 2, "Two Hundred", 3, "Three Hundred", 4, "Four Hundred", 5, "Five Hundred", 6, "Six Hundred", 7, "Seven Hundred", 8, "Eight Hundred", 9, "Nine Hundred", 0, "");
var text firstThouNum = If($Thousands<>"",Case(Floor(ToNumber(Right($Thousands,2))/10),
1, "Ten", 2, "Twenty", 3, "Thirty", 4, "Forty", 5, "Fifty", 6, "Sixty", 7, "Seventy", 8, "Eighty", 9, "Ninety", 0, ""),"");
var text secondThouNum = If($Thousands<>"",Case(ToNumber(Right($Thousands,1)),
1, "One", 2, "Two", 3, "Three", 4, "Four", 5, "Five", 6, "Six", 7, "Seven", 8, "Eight", 9, "Nine", 0, ""));
var text thirdThouNum = If($Thousands<>"",Case(Floor(ToNumber(Right($Thousands,3))/100),
1, "One Hundred", 2, "Two Hundred", 3, "Three Hundred", 4, "Four Hundred", 5, "Five Hundred", 6, "Six Hundred", 7, "Seven Hundred", 8, "Eight Hundred", 9, "Nine Hundred", 0, ""));
var text firstMilNum = If($Millions<>"",Case(Floor(ToNumber(Right($Millions,2))/10),
1, "Ten", 2, "Twenty", 3, "Thirty", 4, "Forty", 5, "Fifty", 6, "Sixty", 7, "Seventy", 8, "Eighty", 9, "Ninety", 0, ""),"");
var text secondMilNum = If($Millions<>"",Case(ToNumber(Right($Millions,1)),
1, "One", 2, "Two", 3, "Three", 4, "Four", 5, "Five", 6, "Six", 7, "Seven", 8, "Eight", 9, "Nine", 0, ""));
var text thirdMilNum = Case(Floor(ToNumber(Right($Millions,3))/100),
1, "One Hundred", 2, "Two Hundred", 3, "Three Hundred", 4, "Four Hundred", 5, "Five Hundred", 6, "Six Hundred", 7, "Seven Hundred", 8, "Eight Hundred", 9, "Nine Hundred", 0, "");
var text tensNum = List(" ", $firstNum, $secondNum);
var text thouNum = List(" ", $firstThouNum, $secondThouNum);
var text millNum = List(" ", $firstMilNum, $secondMilNum);
var text teensCon = If(Contains($tensNum,"ten ")=true,Case($tensNum,
"Ten One", "Eleven",
"Ten Two", "Twelve",
"Ten Three", "Thirteen",
"Ten Four", "Fourteen",
"Ten Five", "Fifteen",
"Ten Six", "Sixteen",
"Ten Seven", "Seventeen",
"Ten Eight", "Eighteen",
"Ten Nine", "Nineteen", $tensNum),$tensNum);
var text thouCon = If(Contains($thouNum,"ten ")=true,Case($thouNum,
"Ten One", "Eleven",
"Ten Two", "Twelve",
"Ten Three", "Thirteen",
"Ten Four", "Fourteen",
"Ten Five", "Fifteen",
"Ten Six", "Sixteen",
"Ten Seven", "Seventeen",
"Ten Eight", "Eighteen",
"Ten Nine", "Nineteen", $thouNum),$thouNum);
var text millCon = If(Contains($millNum,"ten ")=true,Case($millNum,
"Ten One", "Eleven",
"Ten Two", "Twelve",
"Ten Three", "Thirteen",
"Ten Four", "Fourteen",
"Ten Five", "Fifteen",
"Ten Six", "Sixteen",
"Ten Seven", "Seventeen",
"Ten Eight", "Eighteen",
"Ten Nine", "Nineteen", $millNum),$millNum);
var text hundredsNum = $thirdNum & If($teensCon<>""," "& $teensCon,"");
var text hundredsThouNum = $thirdThouNum & If($thouCon<>""," " & $thouCon,"");
var text hundredsMillNum = $thirdMilNum & If($millCon<>"", " "& $millCon,"");
var text finalHund = Trim($hundredsNum);
var text finalThou = Trim($hundredsThouNum & " Thousand");
var text finalMill = Trim($hundredsMillNum & " Million");
var text finalNumber = If(Floor($OriginalValue)<=0,"Zero",
If($hundredsMillNum <> " " and $OriginalValue>=1000000, $finalMill, "")&
If($hundredsThouNum <> "" and $OriginalValue>=1000," "& $finalThou, "")&
If(ToNumber($Hundreds)<>0 and $OriginalValue>=99," "& $finalHund, $teensCon));
Trim($finalNumber & If($numt="1", " Dollar"," Dollars") & [currencyCents])
_________________________[currencyCents] type text/rich text formula
var text cents = If(Contains(ToText([currencySplitCents]), ""), Left(Right(ToText([currencySplitCents]) & "00", "."), 2),"");
var text teenNumCents = List(" ",
Case(Left($cents,1), "1", "Ten", "2", "Twenty", "3", "Thirty", "4", "Forty", "5", "Fifty", "6", "Sixty", "7", "Seventy", "8", "Eighty", "9", "Ninety", "0", ""),
Case(Right($cents,1), "1", "One", "2", "Two", "3", "Three", "4", "Four", "5", "Five", "6", "Six", "7", "Seven", "8", "Eight", "9", "Nine", "0", ""));
If($teenNumCents<>"", " and ", "") & //if teensnum not "" add a space
Case($teenNumCents,"Ten One", "Eleven", "Ten Two", "Twelve", "Ten Three", "Thirteen", "Ten Four", "Fourteen", "Ten Five", "Fifteen", "Ten Six", "Sixteen", "Ten Seven", "Seventeen", "Ten Eight", "Eighteen", "Ten Nine", "Nineteen", $teenNumCents)& If($teenNumCents<>"", " Cents", "")
_________________[currencySplitCents] numeric formula
var number cents = Frac([<currency field>]);
ToNumber(Left(Right(ToText($cents)&"0","."),2))
------------------------------
Jim Harrison
------------------------------
a few changes.
removed dashes between values, added "Dollar"/"Dollars" and cents at the end. Below is all three fields needed with their names underlined. Look for [<currency field>] and replace it with the field in your table.
_____________[currencyToWords] type text/rich text formula
var number OriginalValue = [<currency field>];
var number Value = Round($OriginalValue,0.01);
var text Hundreds=Right(ToText(Int($Value)),3);
var text Thousands = If($Value>=1000,ToText(Int($Value/1000)));
var text Millions = If($Value>=1000000,ToText(Int($Value/1000000)));
var text numt = ToText(Floor($OriginalValue));
var text firstNum = Case(Floor(ToNumber(Right($numt,2))/10),
1, "Ten", 2, "Twenty", 3, "Thirty", 4, "Forty", 5, "Fifty", 6, "Sixty", 7, "Seventy", 8, "Eighty", 9, "Ninety", 0, "");
var text secondNum = Case(ToNumber(Right($numt,1)),
1, "One", 2, "Two", 3, "Three", 4, "Four", 5, "Five", 6, "Six", 7, "Seven", 8, "Eight", 9, "Nine", 0, "");
var text thirdNum = Case(Floor(ToNumber(Right($numt,3))/100),
1, "One Hundred", 2, "Two Hundred", 3, "Three Hundred", 4, "Four Hundred", 5, "Five Hundred", 6, "Six Hundred", 7, "Seven Hundred", 8, "Eight Hundred", 9, "Nine Hundred", 0, "");
var text firstThouNum = If($Thousands<>"",Case(Floor(ToNumber(Right($Thousands,2))/10),
1, "Ten", 2, "Twenty", 3, "Thirty", 4, "Forty", 5, "Fifty", 6, "Sixty", 7, "Seventy", 8, "Eighty", 9, "Ninety", 0, ""),"");
var text secondThouNum = If($Thousands<>"",Case(ToNumber(Right($Thousands,1)),
1, "One", 2, "Two", 3, "Three", 4, "Four", 5, "Five", 6, "Six", 7, "Seven", 8, "Eight", 9, "Nine", 0, ""));
var text thirdThouNum = If($Thousands<>"",Case(Floor(ToNumber(Right($Thousands,3))/100),
1, "One Hundred", 2, "Two Hundred", 3, "Three Hundred", 4, "Four Hundred", 5, "Five Hundred", 6, "Six Hundred", 7, "Seven Hundred", 8, "Eight Hundred", 9, "Nine Hundred", 0, ""));
var text firstMilNum = If($Millions<>"",Case(Floor(ToNumber(Right($Millions,2))/10),
1, "Ten", 2, "Twenty", 3, "Thirty", 4, "Forty", 5, "Fifty", 6, "Sixty", 7, "Seventy", 8, "Eighty", 9, "Ninety", 0, ""),"");
var text secondMilNum = If($Millions<>"",Case(ToNumber(Right($Millions,1)),
1, "One", 2, "Two", 3, "Three", 4, "Four", 5, "Five", 6, "Six", 7, "Seven", 8, "Eight", 9, "Nine", 0, ""));
var text thirdMilNum = Case(Floor(ToNumber(Right($Millions,3))/100),
1, "One Hundred", 2, "Two Hundred", 3, "Three Hundred", 4, "Four Hundred", 5, "Five Hundred", 6, "Six Hundred", 7, "Seven Hundred", 8, "Eight Hundred", 9, "Nine Hundred", 0, "");
var text tensNum = List(" ", $firstNum, $secondNum);
var text thouNum = List(" ", $firstThouNum, $secondThouNum);
var text millNum = List(" ", $firstMilNum, $secondMilNum);
var text teensCon = If(Contains($tensNum,"ten ")=true,Case($tensNum,
"Ten One", "Eleven",
"Ten Two", "Twelve",
"Ten Three", "Thirteen",
"Ten Four", "Fourteen",
"Ten Five", "Fifteen",
"Ten Six", "Sixteen",
"Ten Seven", "Seventeen",
"Ten Eight", "Eighteen",
"Ten Nine", "Nineteen", $tensNum),$tensNum);
var text thouCon = If(Contains($thouNum,"ten ")=true,Case($thouNum,
"Ten One", "Eleven",
"Ten Two", "Twelve",
"Ten Three", "Thirteen",
"Ten Four", "Fourteen",
"Ten Five", "Fifteen",
"Ten Six", "Sixteen",
"Ten Seven", "Seventeen",
"Ten Eight", "Eighteen",
"Ten Nine", "Nineteen", $thouNum),$thouNum);
var text millCon = If(Contains($millNum,"ten ")=true,Case($millNum,
"Ten One", "Eleven",
"Ten Two", "Twelve",
"Ten Three", "Thirteen",
"Ten Four", "Fourteen",
"Ten Five", "Fifteen",
"Ten Six", "Sixteen",
"Ten Seven", "Seventeen",
"Ten Eight", "Eighteen",
"Ten Nine", "Nineteen", $millNum),$millNum);
var text hundredsNum = $thirdNum & If($teensCon<>""," "& $teensCon,"");
var text hundredsThouNum = $thirdThouNum & If($thouCon<>""," " & $thouCon,"");
var text hundredsMillNum = $thirdMilNum & If($millCon<>"", " "& $millCon,"");
var text finalHund = Trim($hundredsNum);
var text finalThou = Trim($hundredsThouNum & " Thousand");
var text finalMill = Trim($hundredsMillNum & " Million");
var text finalNumber = If(Floor($OriginalValue)<=0,"Zero",
If($hundredsMillNum <> " " and $OriginalValue>=1000000, $finalMill, "")&
If($hundredsThouNum <> "" and $OriginalValue>=1000," "& $finalThou, "")&
If(ToNumber($Hundreds)<>0 and $OriginalValue>=99," "& $finalHund, $teensCon));
Trim($finalNumber & If($numt="1", " Dollar"," Dollars") & [currencyCents])
_________________________[currencyCents] type text/rich text formula
var text cents = If(Contains(ToText([currencySplitCents]), ""), Left(Right(ToText([currencySplitCents]) & "00", "."), 2),"");
var text teenNumCents = List(" ",
Case(Left($cents,1), "1", "Ten", "2", "Twenty", "3", "Thirty", "4", "Forty", "5", "Fifty", "6", "Sixty", "7", "Seventy", "8", "Eighty", "9", "Ninety", "0", ""),
Case(Right($cents,1), "1", "One", "2", "Two", "3", "Three", "4", "Four", "5", "Five", "6", "Six", "7", "Seven", "8", "Eight", "9", "Nine", "0", ""));
If($teenNumCents<>"", " and ", "") & //if teensnum not "" add a space
Case($teenNumCents,"Ten One", "Eleven", "Ten Two", "Twelve", "Ten Three", "Thirteen", "Ten Four", "Fourteen", "Ten Five", "Fifteen", "Ten Six", "Sixteen", "Ten Seven", "Seventeen", "Ten Eight", "Eighteen", "Ten Nine", "Nineteen", $teenNumCents)& If($teenNumCents<>"", " Cents", "")
_________________[currencySplitCents] numeric formula
var number cents = Frac([<currency field>]);
ToNumber(Left(Right(ToText($cents)&"0","."),2))
------------------------------
Jim Harrison
------------------------------