Formating numbers

Help with writing and playing macros

Formating numbers

Postby iain_clark » Wed Jul 26, 2006 9:33 am

I am a complete novice in the use of UltraEdit 32 and I'm in need of some assistance. I am editing files which contain columns of figures running into tens of Millions of Pounds. The numbers are quite difficult to read without seperation, is it possible to format the numbers to include thousand seperators, i.e ten million would display as 10,000,000.00. Many thanks in advance. Iain
User avatar
iain_clark
Newbie
 
Posts: 2
Joined: Tue Jul 25, 2006 11:00 pm

Re: Formating numbers

Postby Mofi » Thu Jul 27, 2006 6:11 am

One solution is to use a macro with several regular expression search and replaces. Enable the macro property Continue if a Find with Replace not found for this macro!

The first macro is with UltraEdit style regular expressions.

InsertMode
ColumnModeOff
HexOff
UnixReOff
Top
Find RegExp "^([0-9][0-9][0-9]^)^([0-9][0-9][0-9]^)^([0-9][0-9][0-9]^)"
Replace All "^1,^2,^3"
Find RegExp "^([0-9][0-9]^)^([0-9][0-9][0-9]^)^([0-9][0-9][0-9]^)"
Replace All "^1,^2,^3"
Find RegExp "^([0-9]^)^([0-9][0-9][0-9]^)^([0-9][0-9][0-9]^)"
Replace All "^1,^2,^3"
Find RegExp "^([0-9][0-9][0-9]^)^([0-9][0-9][0-9]^)"
Replace All "^1,^2"
Find RegExp "^([0-9][0-9]^)^([0-9][0-9][0-9]^)"
Replace All "^1,^2"
Find RegExp "^([0-9]^)^([0-9][0-9][0-9]^)"
Replace All "^1,^2"

The same macro with Unix or Perl regular expressions, if you prefer one of these regular expression engines.

InsertMode
ColumnModeOff
HexOff
UnixReOn
Top
Find RegExp "(\d\d\d)(\d\d\d)(\d\d\d)"
Replace All "\1,\2,\3"
Find RegExp "(\d\d)(\d\d\d)(\d\d\d)"
Replace All "\1,\2,\3"
Find RegExp "(\d)(\d\d\d)(\d\d\d)"
Replace All "\1,\2,\3"
Find RegExp "(\d\d\d)(\d\d\d)"
Replace All "\1,\2"
Find RegExp "(\d\d)(\d\d\d)"
Replace All "\1,\2"
Find RegExp "(\d)(\d\d\d)"
Replace All "\1,\2"

An explanation about Regular Expressions and the meanings of the sequences above can be found in help of UltraEdit. If you have numbers larger 999,999,999 you have to add additional find/replaces at top of the macro after the command Top. It should be clear how these replaces must be defined and in which sequence.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4066
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Formating numbers

Postby iain_clark » Thu Jul 27, 2006 11:52 am

Mofi, many thanks. The solution looks obvious when you see it in print, but I struggled with this for many hours without making any progress. Now I need to work out how to delete a character before the number string for each character inserted to maintain the right justification of the column figures.

Again many thanks for your help

Iain.
User avatar
iain_clark
Newbie
 
Posts: 2
Joined: Tue Jul 25, 2006 11:00 pm


Return to Macros