We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
当输入数字的时候,显示数字的最大单位 如: 1,000 在下方展示 千
10 = 10*1 == 1e1 100 = 10*10 == 1e2 1000 = 10*10*10 == 1e3 Math.log10(10) == 1 Math.log10(100) == 2 Math.log10(1000) == 3
根据上面分析10 的幂运算 和对数运算 对应关系 我们定义一个常量
const charCn = ['个','十','百','千','万','十万','百万','千万','亿','十亿','百亿','千亿','兆','十兆','百兆','千兆','京']
Math.floor(Math.log10(1)) // 向下取整(取10的对数) 得到的既是 对应值的下标
function getCharName(value) { const charCnIndex = Math.floor(Math.log10(value)) return charCn[charCnIndex] }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
需求如下
当输入数字的时候,显示数字的最大单位
如: 1,000 在下方展示 千
实现思路
根据上面分析10 的幂运算 和对数运算 对应关系
我们定义一个常量
获取值的单位下标
最后,我们封装个函数
The text was updated successfully, but these errors were encountered: