# Convert Numbers to Words

## Recommended Posts

Is there a rule to be able to convert a number to words? Like so: 500 becomes "Five Hundred", 125 becomes "One Hundred Twenty Five" and so forth.
##### Share on other sites

Hey, anything's possible, right? /me looks around...

Is there a limit to how high your numbers go? 100s? 1000s?

```var number = Field("Number"); // this is the only line you need to edit (see comment on line 108)

function tens(tens,ones){
switch (Int(tens)){
case 9:
var tensPlace = "Ninety ";
break;

case 8:
var tensPlace = "Eighty ";
break;

case 7:
var tensPlace = "Seventy ";
break;

case 6:
var tensPlace = "Sixty ";
break;

case 5:
var tensPlace = "Fifty ";
break;

case 4:
var tensPlace = "Forty ";
break;

case 3:
var tensPlace = "Thirty ";
break;

case 2:
var tensPlace = "Twenty ";
break;

case 1:
switch (Int(ones)) {
case 9:
var tensPlace = "Nineteen";
break;

case 8:
var tensPlace = "Eighteen";
break;

case 7:
var tensPlace = "Seventeen";
break;

case 6:
var tensPlace = "Sixteen";
break;

case 5:
var tensPlace = "Fifteen";
break;

case 4:
var tensPlace = "Fourteen";
break;

case 3:
var tensPlace = "Thirteen";
break;

case 2:
var tensPlace = "Twelve";
break;

case 1:
var tensPlace = "Eleven";
break;

default:
var tensPlace = "Ten";
}
break;

default:
var tensPlace = "";
}
return tensPlace;
}

function ones(tens,ones){
if (Int(tens) != 1){
switch (Int(ones)){
case 9:
var onesPlace = "Nine ";
break;

case 8:
var onesPlace = "Eight ";
break;

case 7:
var onesPlace = "Seven ";
break;

case 6:
var onesPlace = "Six ";
break;

case 5:
var onesPlace = "Five ";
break;

case 4:
var onesPlace = "Four ";
break;

case 3:
var onesPlace = "Three ";
break;

case 2:
var onesPlace = "Two ";
break;

case 1:
var onesPlace = "One ";
break;

default:
var onesPlace = "";
}
} else var onesPlace = "";
return onesPlace;
}

var digits = number.split("");
var places = digits.length;

// add "case 5:" for 10,000s, "case 6:" for 100,000s, etc.
switch (places) {
case 4:
var numberText = ones(0,digits) + "Thousand " + ones(0,digits);
if (ones(0,digits) != "") numberText += "Hundred ";
numberText += tens(digits,digits) + ones(digits,digits);
break;

case 3:
var numberText = ones(0,digits) + "Hundred " + tens(digits,digits) + ones(digits,digits);
break;

case 2:
var numberText = tens(digits,digits) + ones(digits,digits);
break;

default:
var numberText = ones(0,digits);

}

return numberText;```

##### Share on other sites

Thanks Guys. I feel like an idiot. I searched different javascript language references online. I didn't even think about looking for and actual script. Looks like this will work.

#### Archived

This topic is now archived and is closed to further replies.

×

• #### FusionPro.com

• MarcomCentral
×
• Create New...