Jump to content

Convert Numbers to Words


MartyrSyx

Recommended Posts

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[0]) + "Thousand " + ones(0,digits[1]);
       if (ones(0,digits[1]) != "") numberText += "Hundred ";
       numberText += tens(digits[2],digits[3]) + ones(digits[2],digits[3]);
break;

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

case 2:
var numberText = tens(digits[0],digits[1]) + ones(digits[0],digits[1]);
break;

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

}

return numberText;

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...