Play Flash Games


© 2007 Red Computer

HTML Howto, CSS Howto, JavaScript Howto, PHP Howto, Windows Howto
Google

JA Bahttext()


For the currency you can not traslate number directly by reading form number to text. There is a format in Thai language to read currency.

<script language=JavaScript>
function bahttext(n){
	var txtnum1 = new Array("ศูนย์","หนึ่ง","สอง","สาม","สี่","ห้า","หก","เจ็ด","แปด","เก้า","สิบ");
	var txtnum2 = new Array("","สิบ","ร้อย","พัน","หมื่น","แสน","ล้าน");
	var  num = n.replace(",","");
	num = num.replace(" ","");
	num = num.replace("บาท","");
	num = num.split(".");
	if (num.length>2) {
		return "ทศนิยมมีได้เพียง 2 ตัวนะจ๊ะ";
	}
	var len = num[0].length;
	var txt = "";
	for (var i=0; i < len; i++) {
		numt=num[0].toString();
		var n = numt.substr(i,1);
		if (n != 0) {
			if (i==(len-1) && n==1)
				txt += "เอ็ด";
			else if (i==(len-2) && n==2)
				txt += "ยี่"; 
			else if (i==(len-2) && n==1)
				txt += "";
			else
				txt += txtnum1[n];
			txt += txtnum2[len - i - 1];
		}
  }
  txt += "บาท";
  if(num[1]=="0" || num[1]=="00" || num[1]=="") {
		txt += "ถ้วน";
  } else {
		len = num[1].length;
		for(var i=0; i < len; i++) {
			numt=num[1].toString();
			var n = numt.substr(i,1);
			if (n != 0){
				if (i==(len-1) && n==1)
					txt += "เอ็ด";
				else if (i==(len-2) && n==2)
					txt += "ยี่";
				else if (i==(len-2) && n==1)
					txt += "";
				else
					txt += txtnum1[n];
				txt += txtnum2[len - i -1];
			}
		}
		if (numt.substr(1,1)=="0") 
			txt += "สิบ";
		txt += "สตางค์";
	}
	return txt;
}

// try to print to see the result
document.write(bahttext(2150238));

</script>

In input datetime is bahttext(2150238) This is the output result :





Visitor's Comment

Post a Comment
Comment
Name :
E-mail :

HOME | HTML | CSS | JavaScript | PHP | XML | SQL | Virus Fix | Windows | Downloads | Links