Browse Groups

• Has anyone written any clips to perform rounding of numbers? I want to round up if the 4th digit is 5-9. I just change it to zero if it is 1-4. Here are a
Message 1 of 8 , Feb 4, 2011
View Source
Has anyone written any clips to perform rounding of numbers? I want to round up if the 4th digit is 5-9. I just change
it to zero if it is 1-4.

Here are a couple example numbers:
19945
19967

The first result should be 19900 (which is easy, and I do that first, using a range with [1-4])
The second result should be 20000 (based on the 4th digit rounding up.)

Thanks,
John

[Non-text portions of this message have been removed]
• see message 10156 ROUND(1.5955*100)/100 = 1.600000 (Rounded up to the nearest cent) ROUND(1.59112*100)/100 = 1.590000 (Rounded down to the nearest cent)
Message 1 of 8 , Feb 4, 2011
View Source
see message 10156
ROUND(1.5955*100)/100 = 1.600000 (Rounded up to the nearest cent)
ROUND(1.59112*100)/100 = 1.590000 (Rounded down to the nearest cent)
ROUND(5285/100)*100 = 5300.00 (Rounded up to the nearest hundred)
ROUND(5249/100)*100 = 5200.00 (Rounded down to the nearest hundred)

CEIL rounds the number up from zero to the next integer if it has a
fractional part and it is a positive number. If it is a negative number,
it rounds the number up towards zero to the next integer.
It does not round it if the number does not have a decimal part.

CEIL(7.9112) = 8.000000000000000
CEIL(-7.9112) = -7.000000000000000
CEIL(7.0000001) = 8.000000000000000
CEIL(-7.0000001) = -7.000000000000000
CEIL(7) = 7.000000000000000
CEIL(-7) = -7.000000000000000

FLOOR rounds the number down toward zero to the next integer if it has a
fractional part and it is a positive number. If it is a negative number it
rounds the number down from zero to the next integer.
It makes no change if it does not have a decimal part.

FLOOR(7.9112) = 7.000000000000000
FLOOR(-7.9112) = -8.000000000000000
FLOOR(7.0000001) = 7.000000000000000
FLOOR(-7.0000001) = -8.000000000000000
FLOOR(7) = 7.000000000000000
FLOOR(-7) = -7.000000000000000

On 2/4/2011 11:15 PM, John Shotsky wrote:
> Has anyone written any clips to perform rounding of numbers? I want to round up if the 4th digit is 5-9. I just change
> it to zero if it is 1-4.
>
> Here are a couple example numbers:
> 19945
> 19967
>
> The first result should be 19900 (which is easy, and I do that first, using a range with [1-4])
> The second result should be 20000 (based on the 4th digit rounding up.)
>
> Thanks,
> John
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> Fookes Software: http://www.fookes.com/
> NoteTab website: http://www.notetab.com/
> NoteTab Discussion Lists: http://www.notetab.com/groups.php
>
> ***
>
>
>
>
• Thanks! I need something simpler. I don t want to use a loop for this. I can round down with a simple replace, if the 4th digit is 1-4. After that, if the 4th
Message 1 of 8 , Feb 4, 2011
View Source
Thanks!

I need something simpler. I don't want to use a loop for this. I can round down with a simple replace, if the 4th digit
is 1-4.

After that, if the 4th digit is anything except 0-4, it should add one to the first three digits. If it's not possible
without a loop, I'll probably round that down anyway - it isn't finance or math, it is just getting back to only 3
significant digits.

Regards,
John

From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of Don
Sent: Friday, February 04, 2011 8:24 PM
To: ntb-clips@yahoogroups.com
Subject: Re: [Clip] Rounding clips

see message 10156
ROUND(1.5955*100)/100 = 1.600000 (Rounded up to the nearest cent)
ROUND(1.59112*100)/100 = 1.590000 (Rounded down to the nearest cent)
ROUND(5285/100)*100 = 5300.00 (Rounded up to the nearest hundred)
ROUND(5249/100)*100 = 5200.00 (Rounded down to the nearest hundred)

CEIL rounds the number up from zero to the next integer if it has a
fractional part and it is a positive number. If it is a negative number,
it rounds the number up towards zero to the next integer.
It does not round it if the number does not have a decimal part.

CEIL(7.9112) = 8.000000000000000
CEIL(-7.9112) = -7.000000000000000
CEIL(7.0000001) = 8.000000000000000
CEIL(-7.0000001) = -7.000000000000000
CEIL(7) = 7.000000000000000
CEIL(-7) = -7.000000000000000

FLOOR rounds the number down toward zero to the next integer if it has a
fractional part and it is a positive number. If it is a negative number it
rounds the number down from zero to the next integer.
It makes no change if it does not have a decimal part.

FLOOR(7.9112) = 7.000000000000000
FLOOR(-7.9112) = -8.000000000000000
FLOOR(7.0000001) = 7.000000000000000
FLOOR(-7.0000001) = -8.000000000000000
FLOOR(7) = 7.000000000000000
FLOOR(-7) = -7.000000000000000

On 2/4/2011 11:15 PM, John Shotsky wrote:
> Has anyone written any clips to perform rounding of numbers? I want to round up if the 4th digit is 5-9. I just change
> it to zero if it is 1-4.
>
> Here are a couple example numbers:
> 19945
> 19967
>
> The first result should be 19900 (which is easy, and I do that first, using a range with [1-4])
> The second result should be 20000 (based on the 4th digit rounding up.)
>
> Thanks,
> John
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> Fookes Software: http://www.fookes.com/
> NoteTab website: http://www.notetab.com/
> NoteTab Discussion Lists: http://www.notetab.com/groups.php
>
> ***
>
>
>
>

[Non-text portions of this message have been removed]
• ... Why? ^!Calc does correct rounding all on its own. Try the following after highlighting your number. N.B: It seems ^!Calc can t be nested, so I had to make
Message 1 of 8 , Feb 4, 2011
View Source
John Shotsky wrote:
> Has anyone written any clips to perform rounding of numbers?

Why? ^!Calc does correct rounding all on its own. Try the following
N.B: It seems ^!Calc can't be nested, so I had to make it two lines.

^!InsertSelect ^\$Calc(^\$GetSelection\$/100;0)\$
^!InsertText ^\$Calc(^\$GetSelection\$*100;0)\$

Axel
• ... John, Are you dealing with full text or a list of numbers? If it s full-text the following clip could possibly work... ^!SetHintInfo Working...
Message 1 of 8 , Feb 5, 2011
View Source
--- In ntb-clips@yahoogroups.com, "John Shotsky" <jshotsky@...> wrote:
>
> Here are a couple example numbers:
> 19945
> 19967
>
> The first result should be 19900 (...) The second result
> should be 20000 (based on the 4th digit rounding up.)

John,

Are you dealing with full text or a list of numbers? If it's full-text the following clip could possibly work...

^!SetHintInfo Working...
^!SetScreenUpdate Off
^!Jump 1
^!Find "\b\d{5}\b" RS
^!IfError End
^!InsertSelect ^\$Calc(^\$Calc(^\$GetSelection\$/100;0)\$*100)\$
^!Goto Skip_-3

If it's a list of numbers you could speed up the job with...

^!SetHintInfo Working...
^!SetScreenUpdate Off
; Copy selected numbers to the clipboard...
^!SetClipboard ^\$GetDocListAll("\d{3}[0-4][0-9]";"\$0\r\n")\$
; ...and remove those numbers from the list
^!Replace "^\d{3}[0-4][0-9](\R|\Z)" >> "" WARS
; Round remaining numbers
^!Jump 1
^!Find "^\d{5}\$" RS
^!IfError Out
^!InsertSelect ^\$Calc(^\$Calc(^\$GetSelection\$/100;0)\$*100)\$
^!Goto Skip_-3
:Out
; Insert selected numbers from clipboard
^!InsertText ^P^\$GetClipboard\$
; Replace all the last two digits with '00'
^!Replace "^\d{3}\K\d{2}\$" >> "00" WARS

I've tested both clips with a list of 10,000 numbers. For me, the first clip needs 38 sec, the second clip needs 17 sec to do the job.

Regards,
Flo

P.S. The ^\$Calc\$ is borrowed from Axel Berger showing how it can be nested ;-)
• Thanks, Flo, that works great. And, I learned something again, as usual. :-) Regards, John Recipe formatting tools:
Message 1 of 8 , Feb 5, 2011
View Source
Thanks, Flo, that works great. And, I learned something again, as usual. :-)

Regards,
John
Recipe formatting tools: <http://recipetools.gotdns.com/> http://recipetools.gotdns.com
RecipeTools FTP Site: <ftp://recipetoolsftp.gotdns.com/> ftp://recipetoolsftp.gotdns.com
Beaverton Weather: <http://shotsky.gotdns.com/> http://shotsky.gotdns.com

From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of flo.gehrke
Sent: Saturday, February 05, 2011 10:02 AM
To: ntb-clips@yahoogroups.com
Subject: [Clip] Re: Rounding clips

--- In ntb-clips@yahoogroups.com <mailto:ntb-clips%40yahoogroups.com> , "John Shotsky" <jshotsky@...> wrote:
>
> Here are a couple example numbers:
> 19945
> 19967
>
> The first result should be 19900 (...) The second result
> should be 20000 (based on the 4th digit rounding up.)

John,

Are you dealing with full text or a list of numbers? If it's full-text the following clip could possibly work...

^!SetHintInfo Working...
^!SetScreenUpdate Off
^!Jump 1
^!Find "\b\d{5}\b" RS
^!IfError End
^!InsertSelect ^\$Calc(^\$Calc(^\$GetSelection\$/100;0)\$*100)\$
^!Goto Skip_-3

If it's a list of numbers you could speed up the job with...

^!SetHintInfo Working...
^!SetScreenUpdate Off
; Copy selected numbers to the clipboard...
^!SetClipboard ^\$GetDocListAll("\d{3}[0-4][0-9]";"\$0\r\n")\$
; ...and remove those numbers from the list
^!Replace "^\d{3}[0-4][0-9](\R|\Z)" >> "" WARS
; Round remaining numbers
^!Jump 1
^!Find "^\d{5}\$" RS
^!IfError Out
^!InsertSelect ^\$Calc(^\$Calc(^\$GetSelection\$/100;0)\$*100)\$
^!Goto Skip_-3
:Out
; Insert selected numbers from clipboard
^!InsertText ^P^\$GetClipboard\$
; Replace all the last two digits with '00'
^!Replace "^\d{3}\K\d{2}\$" >> "00" WARS

I've tested both clips with a list of 10,000 numbers. For me, the first clip needs 38 sec, the second clip needs 17 sec
to do the job.

Regards,
Flo

P.S. The ^\$Calc\$ is borrowed from Axel Berger showing how it can be nested ;-)

[Non-text portions of this message have been removed]
• ... Thanks, John! I just found out that it s faster with ^!InsertText ^\$Calc... -- there s no ^!InsertSelect ^\$Calc... needed here. New runtime: 20 resp.
Message 1 of 8 , Feb 5, 2011
View Source
--- In ntb-clips@yahoogroups.com, "John Shotsky" <jshotsky@...> wrote:
>
> Thanks, Flo, that works great...

Thanks, John!

I just found out that it's faster with '^!InsertText ^\$Calc...' -- there's no '^!InsertSelect ^\$Calc...' needed here. New runtime: 20 resp. 11 sec with 10,000 lines.

Flo
• ... So nesting Calcs does work after. It does here too now, no idea what that error I caught last time was about. Axel
Message 1 of 8 , Feb 5, 2011
View Source
John Shotsky wrote:
> ^!InsertSelect ^\$Calc(^\$Calc(^\$GetSelection\$/100;0)\$*100)\$

So nesting Calcs does work after. It does here too now, no idea what
that error I caught last time was about.

Axel
Your message has been successfully submitted and would be delivered to recipients shortly.
• Changes have not been saved
Press OK to abandon changes or Cancel to continue editing
• Your browser is not supported
Kindly note that Groups does not support 7.0 or earlier versions of Internet Explorer. We recommend upgrading to the latest Internet Explorer, Google Chrome, or Firefox. If you are using IE 9 or later, make sure you turn off Compatibility View.