猫史档案馆


【教程】用人话表示数字

用户:卑微OIer卑微OIer查看:1 回复:15 评论:1 创建时间:2022-04-01T11:11:19


------------------------------------------------------------------------------

老师:xdm读一下114514114514

同学:(心里t.m的,怎么长让我则么读?)

老师:1145.141114514亿啊

同学:太长了,四舍五入1145.14亿

 

所以本教程的内容是如何将这臭数字转化一下

Step1 个十百千万

在百度上搜索一下数字单位,我们立马就找到了

const digital = ['','万','亿','兆','京','垓','秭','穰','沟','涧','正','载','极',
'恒河沙','阿僧之','那由他','不可思议','无量','大数','全仕祥','古戈尔'];

Step2 写代码

前提了解 log函数

    const logs=Math.log10(number);
    const behind = Math.floor(logs/4);
    let fronts = number/Math.pow(10,behind*4);
    fronts = Math.floor(fronts*1000)/1000;
    console.log(fronts+digital[behind]);

封装函数)

console.clear();
function turnDigit(number){
    const digital = ['','万','亿','兆','京','垓','秭','穰','沟','涧','正','载','极','恒河沙','阿僧之','那由他','不可思议','无量','大数','全仕祥','古戈尔'];
    const logs=Math.log10(number);
    const behind = Math.floor(logs/4);
    let fronts = number/Math.pow(10,behind*4);
    fronts = Math.floor(fronts*1000)/1000;
    return (fronts+digital[behind]);
}

效果

123 => 123

114514 => 11.45万

 


回复

上一页1 页 / 共 1下一页
用户_869149用户_869149

沙发

点赞0


评论


用户_869149用户_869149

板凳

点赞0


评论


用户_869149用户_869149

前排

点赞0


评论


用户_869149用户_869149

地板

点赞0


评论


用户_869149用户_869149

天花板

点赞0


评论


用户_869149用户_869149

顶顶顶

点赞0


评论


用户_869149用户_869149

NB

点赞0


评论


Architect_煎饼Architect_煎饼

符号语言变文字语言()()()

点赞2


评论


云游box3der尖头叉子云游box3der尖头叉子

啊啊啊,全被抢了诶,那我来个龙椅吧()()()

点赞0


评论


难起的名字难起的名字

hhc

点赞0


评论


yee089yee089

下次教狗语表示(doge)

点赞1


评论


难起的名字难起的名字

真不错()

点赞0


评论


卑微OIer卑微OIer

喵d

点赞0


评论


全能代码师全能代码师

nb!!

点赞0


评论


灵清帝王吃爆一切厕所灵清帝王吃爆一切厕所

喵d

点赞0


评论