Use Regex to add 0 after first decimal - Javascript RegExp

Javascript examples for RegExp:Match Number

Description

Use Regex to add 0 after first decimal

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//from  w  w w .  j a va2 s.  c  o  m
var array = [10, 19.5, 13.99, 9.09];
for(var i=0; i< array.length;i++){
    if(/[0-9].[0-9]{1}$/.test(array[i])) {
        console.log(array[i]);
        array[i] = array[i]+'0';
    }
}
console.log(array);
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials