Created
June 25, 2020 06:45
-
-
Save itsmereal/fd95044c7c4fd8f8575c0899bd22f2ea to your computer and use it in GitHub Desktop.
Add '0' to string if HH:MM.SS string is not formatted with double digit seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var str = '31:21.92'; | |
var markS = str.match('[^.]*$'); // Find everything after '.' | |
if (markS.toString().length < 2) { // Check lenght of output | |
console.log(markS); | |
console.log(str + '0'); // When oput is less than 2 it needs an extra 0 | |
} else { | |
console.log(markS); | |
console.log('It\'s OK'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment