Converting vs Rounding

This forum is user-to-user based and not regularly monitored by IDM.
Please see the note at the top of this page on how to contact IDM.

Converting vs Rounding

Postby unk-remus » Mon Jun 10, 2013 6:53 pm

I have comma delimited data sets containing an identifier and coordinate values for that identifier:
100100,1841538.5398853,517594.987079397
Does converting to fixed column have anything to do with rounding?
Example: I need to the keep the identifier 100100 and round the first coordinate value of 1841538.5398853 to 1841538.540
and round the second coordinate value of 517594.987079397 to 517594.987.
I have several data sets I would like to round in this manner - each contains approximately 600 lines/records.
Any suggestions?
unk-remus
Newbie
 
Posts: 2
Joined: Sat Jul 30, 2011 4:17 pm

Re: Converting vs Rounding

Postby Mofi » Tue Jun 11, 2013 2:31 am

unk-remus wrote:Does converting to fixed column have anything to do with rounding?

No! Converting to fixed column means replacing the separartor (= comma) by spaces so that every data column has same width.

Code: Select all
100100,1841538.5998853,517594.987
100100,1841538.530,517594.987
100100,1841538.538,517594.987

The block above is for example converted to:

Code: Select all
100100 1841538.5998853 517594.987
100100 1841538.530     517594.987
100100 1841538.538     517594.987


A rounding as you would like requires converting the value strings into floating point numbers, then round them depending on 4 post comma digit and write the rounded float value back to file as string. Spreadsheet applications like Excel support that. With an UltraEdit script it would be possible to.

But I have written here quickly an UltraEdit macro which does most of the roundings by running Perl regular expression replaces.

Code: Select all
InsertMode
ColumnModeOff
HexOff
PerlReOn
Top
Find MatchCase RegExp "(\.\d\d\d)[0-4]\d+"
Replace All "\1"
Find MatchCase RegExp "(\.\d\d)0\d+"
Replace All "\11"
Find MatchCase RegExp "(\.\d\d)1\d+"
Replace All "\12"
Find MatchCase RegExp "(\.\d\d)2\d+"
Replace All "\13"
Find MatchCase RegExp "(\.\d\d)3\d+"
Replace All "\14"
Find MatchCase RegExp "(\.\d\d)4\d+"
Replace All "\15"
Find MatchCase RegExp "(\.\d\d)5\d+"
Replace All "\16"
Find MatchCase RegExp "(\.\d\d)6\d+"
Replace All "\17"
Find MatchCase RegExp "(\.\d\d)7\d+"
Replace All "\18"
Find MatchCase RegExp "(\.\d\d)8\d+"
Replace All "\19"
Find MatchCase RegExp "\.\d{4,}"
IfFound
Key HOME
Find MatchCase RegExp "(\.\d)09\d+"
Replace All "\110"
Find MatchCase RegExp "(\.\d)19\d+"
Replace All "\120"
Find MatchCase RegExp "(\.\d)29\d+"
Replace All "\130"
Find MatchCase RegExp "(\.\d)39\d+"
Replace All "\140"
Find MatchCase RegExp "(\.\d)49\d+"
Replace All "\150"
Find MatchCase RegExp "(\.\d)59\d+"
Replace All "\160"
Find MatchCase RegExp "(\.\d)69\d+"
Replace All "\170"
Find MatchCase RegExp "(\.\d)79\d+"
Replace All "\180"
Find MatchCase RegExp "(\.\d)89\d+"
Replace All "\190"
Find MatchCase RegExp "\.\d{4,}"
EndIf

The macro is not complete as it does not round a value like 1841538.5998853 to 1841538.600 or a value like 1999999.9995013 to 2000000.000.

In other words if a round up is necessary and second post comma digit has the value 9, the value is not rounded. The last find selects the first number where a manual round must be done if there is such a value in the file. After making this round manually, search with Perl regular expression engine for \.\d{4,} for other values which must be rounded manually after executing this macro.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 4049
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Converting vs Rounding

Postby unk-remus » Tue Jun 11, 2013 11:33 am

Thanks M
unk-remus
Newbie
 
Posts: 2
Joined: Sat Jul 30, 2011 4:17 pm


Return to UltraEdit General Discussion