Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                
//将数字转换成中文大写的表示,处理到万级别,例如 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

Console