Created
April 24, 2024 13:53
-
-
Save trycf/c3a70b3dd2b9ea9b2ff3ec51bbc490f0 to your computer and use it in GitHub Desktop.
TryCF Gist
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
<cfscript> | |
//num = "1,234,567.89"; | |
//num = "1.234.567,89"; | |
//num = "1’234’567.89"; | |
//num = "1 234 576.89"; | |
//num = "1234567.89"; | |
//num = "33"; | |
num = "100.000,484389"; | |
function standardiseDecimalNumber(num) { | |
numDelimiters = reReplace(num, "\d", "", "all"); | |
if(numDelimiters == "" || len(numDelimiters) == 1) { | |
return num; | |
} | |
thousandsDelimiter = numDelimiters[1]; | |
decimalDelimiter = numDelimiters[len(numDelimiters)]; | |
num = replace(num, thousandsDelimiter, "", "all"); | |
if(find(decimalDelimiter, num)) { | |
num = replace(num, decimalDelimiter, ".", "all"); | |
} | |
return num; | |
} | |
dump(standardiseDecimalNumber(num)); | |
</cfscript> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment