Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              
//将数字转换成中文大写的表示,处理到万级别,例如 12345 -> 一万二千三百四十五
//精确到万
var re=toLowerNum1(33422323)
var res=toLowerNum2(33422323)

console.log(re)
console.log(res)
function toLowerNum1(num){
	var number = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'] // 定义中文数字
	var unit = ['', '十', '百', '千', '万'] // 定义中文基
	var resultStr = []
	var len = 0 // 数字长
	var lastNumNotZero = false
	while(num){
		let n = num % 10
		let u = len >= unit.length ? len % 5 + 1 : len % 5

		// 添加基
		// if(n || (len >= unit.length && lastNumNotZero))
		if(
			n // 当前位存在
			|| // 或者
			( u == unit.length - 1 && // u 和 长度均为 最后一位unit
				len == unit.length - 1
			)
		)
			resultStr.unshift(unit[u])

		// 处理数
		if(
			n || lastNumNotZero // 当前位和前一位不都为零则处理
			&& 
			u !== unit.length - 1 // 且当前位不为最后一位基
		) 
			resultStr.unshift(number[n])
		lastNumNotZero = !!n
		len++
		num = Math.floor(num / 10)
	}
	return resultStr.join('')
}


//精确到百万
function toLowerNum2(num){
	var number = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'] // 定义中文数字
	var unit = ['', '十', '百', '千', '万'] // 定义中文基
	var resultStr = []
	var len = 0 // 数字长
	var lastNumNotZero = false
	while(num){
		let n = num % 10
		let u = len >= unit.length ? len % 5 + 1 : len % 5

		// console.log(n, u, len)
		// 添加基
		// if(n || (len >= unit.length && lastNumNotZero))
		if(
			n // 当前位存在
			|| // 或者
			( u == unit.length - 1 && // u 和 长度均为 最后一位unit
				len == unit.length - 1
			)
		)
			resultStr.unshift(unit[u])

		// 处理数
		if(
			n || lastNumNotZero // 当前位和前一位不都为零则处理
			&& 
			u !== unit.length - 1 // 且当前位不为最后一位基
		) 
			resultStr.unshift(number[n])
		lastNumNotZero = !!n
		len++
		num = Math.floor(num / 10)
	}
	return resultStr.join('')
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console