js 钱大小写转换,和 数值格式化

var num=56.45678;
var rs1=num.toExponential(2);//rs1的值为5.65e+1
var rs2=num.toFixed(2);//rs的值为56.45
var rs3=num.toPrecision(2);//rs的值为56

function regInput(reg)
{
	var srcElem = event.srcElement
	var oSel = document.selection.createRange()
	oSel = oSel.duplicate()
	 
	oSel.text = ""
	var srcRange = srcElem.createTextRange()
	oSel.setEndPoint("StartToStart", srcRange)
	var num = oSel.text + String.fromCharCode(event.keyCode) + srcRange.text.substr(oSel.text.length)
	event.returnvalue = reg.test(num)
}

//转小写
function aNumber(num)
{
	var numArray = new Array()
	var unit = "亿万元$"
	for (var i=0; i Math.pow(10, 12)) return ""
	var cn = "零壹贰叁肆伍陆柒捌玖"
	var unit = new Array("拾百千", "分角")
	var unit1= new Array("万亿", "")
	var numArray = num.toString().split(".")
	var start = new Array(numArray[0].length-1, 2)
	function toChinese(num, index)
	{
		var num = num.replace(/\d/g, function ($1)
		{
			return cn.charAt($1)+unit[index].charAt(start--%4 ? start%4 : -1)
		})
		return num
	}
	for (var i=0; i 
 

你可能感兴趣的:(钱的大小写转换)