Created
June 12, 2019 23:59
-
-
Save shanerk/f901f65d95e9abcdcc26596442072ac7 to your computer and use it in GitHub Desktop.
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
/** | |
* Checks and converts strings when they contain accounting negative format ($1,000.00) | |
* to standard negative format -$1,000.00 | |
* | |
* @param str Input String to evaluate | |
* | |
* @return String containing converted value, or original value if there was no match found | |
*/ | |
public static String toStandardNegative(String str) { | |
Pattern negPattern = Pattern.compile('^\\((.+)\\)$'); | |
Matcher negMatcher = negPattern.matcher(str); | |
if (negMatcher.matches()) { | |
str = '-' + negMatcher.group(1); | |
} | |
return str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment