Skip to content

Instantly share code, notes, and snippets.

@shanerk
Created June 12, 2019 23:59
Show Gist options
  • Save shanerk/f901f65d95e9abcdcc26596442072ac7 to your computer and use it in GitHub Desktop.
Save shanerk/f901f65d95e9abcdcc26596442072ac7 to your computer and use it in GitHub Desktop.
/**
* 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