Created
October 26, 2021 14:55
-
-
Save vbresan/11b9b12a510a8996d58e92347e683acc to your computer and use it in GitHub Desktop.
Simplifies string in currency format. Removes all thousands separators, keeps only decimal separator. Separators can be "," or ".".
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
function parseInputNumber(value) { | |
let last = Math.max(value.lastIndexOf(","), value.lastIndexOf(".")); | |
if (last == -1) { | |
return value; | |
} | |
let parts = value.split(/[.,]/); | |
let parsed = parts.slice(0, -1).join(""); | |
if (parts.slice(-1)[0].length <= 2) { | |
parsed += value[last]; | |
} | |
parsed += parts.slice(-1); | |
return parsed; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment