Home > Enterprise >  Replace the numbers with *
Replace the numbers with *

Time:10-06

How to replace the last two digits with asterisks using JavaScript Example: console.log(Math.random()) // 0.6334249899746089 || 0.63342498997460**
I gave you as an example random

CodePudding user response:

To replace the last 2 digits with some characters, firstly convert it to a string and then, using the slice() method, append the characters. You can read more about the slice() method in its MDN Documentation.

let numberAsString = Math.random().toString(); //your number as a string
let result = numberAsString.slice(0, -2)   '**'; //cut and append your asterisks
  • Related