Last active
April 17, 2021 23:53
-
-
Save dav1app/be8b183b0442cb2eda225e2be37a390a to your computer and use it in GitHub Desktop.
A nice way to parse money in JS
This file contains hidden or 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
export default correctInput(input){ | |
let result | |
result = input.replace(',','') | |
result = parseInt(result) | |
result = result.toString() | |
result = result.padStart(3,'0') | |
result = result.substr(0,result.length-2)+","+ result.substr(result.length-2,2) | |
return result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment