[英]Replace the numbers with *
How to replace the last two digits with asterisks using JavaScript Example: console.log(Math.random()) // 0.6334249899746089 || 0.63342498997460**
如何使用 JavaScript 将最后两位数字替换为星号 示例:
console.log(Math.random()) // 0.6334249899746089 || 0.63342498997460**
console.log(Math.random()) // 0.6334249899746089 || 0.63342498997460**
I gave you as an example random我随机给你举个例子
To replace the last 2 digits with some characters, firstly convert it to a string and then, using the slice()
method, append the characters.要用一些字符替换最后 2 位数字,首先将其转换为字符串,然后使用
slice()
方法,append 个字符。 You can read more about the slice()
method in its MDN Documentation .您可以在其MDN 文档中阅读有关
slice()
方法的更多信息。
let numberAsString = Math.random().toString(); //your number as a string
let result = numberAsString.slice(0, -2) + '**'; //cut and append your asterisks
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.