-1

Need currency post-processor to be used for all currency amounts. The logic for the post-processor should handle the following cases:

14.978.00 -> 14,978.00 

14.97800 -> 14,978.00 

14,97800 -> 14,978.00 

Logic is as follows:

  1. If the number is well formed (commas in correct place and at most one decimal point found with 2 digits after it)- then do nothing.

  2. Else if a decimal point is found in a position where a comma would make sense, then change the decimal point to a comma (change decimal to a comma if the decimal has 3 or more numbers to the right of it)

  3. After doing step 2, Any number that ends in a comma followed by 5 digits (,nnnnn) should be converted to ,nnn.nn.

Amar
  • 13,103
  • 7
  • 50
  • 69

1 Answers1

0

s/\.(\d{3})/,$1/
Match a point followed by 3 digits, replace that by a comma followed by those same 3 digits (which were captured).

s/,(\d{3})(\d{2})$/,$1.$2/
Match a comma, followed by 5 digits (a group of 3 and a group of 2) at the end of the string, replace that by a comma, the first 3 digits (which were captured), a point, and the last 2 digits (which were captured).

SQB
  • 3,583
  • 1
  • 24
  • 44
  • i have put ^([0-9]{2,3})\.([0-9]{3})\.([0-9]{2})$|^([0-9]{2,3})\,([0-9]{3})([0-9]{2})$|^([0-9]{2,3})\.([0-9]{3})([0-9]{2})$ in regular expression and $1\,$2\.$3 in replacement, but it is just displaying ,. in output, it is not picking up the integer values – Archit Gupta Nov 11 '13 at 10:11
  • That would mean it is matching but not capturing, which is weird. However, that's not what I suggested _at all_. – SQB Nov 11 '13 at 10:27