regex - How can I use JavaScript's replace function to divide a matched number by 100? -


i trying divide regex-matched number in string format 100 within javascript's replace function:

var number = "4354543";  var result = number.replace(/(\d+)/, '$1/100'); console.log(result);  -> printing 4354543/100 

the answer should 43545.43, instead i'm getting "4354543/100".

is possible achieve this?

if know input strings @ least 3 digits, simple solution insert decimal separator before last 2 digits.

var number = "4354543";   var result = number.replace(/(\d+)(\d{2})/, '$1.$2');  console.log(result);

however, using function second argument .replace, the answer james thorpe does, gives more flexibility.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -