<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CTLUG &#187; math</title>
	<atom:link href="http://www.supergluetech.com/wp/tag/math/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.supergluetech.com/wp</link>
	<description>Cookeville TN Linux Users Group</description>
	<lastBuildDate>Thu, 10 Jun 2010 05:21:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simple round function for Perl</title>
		<link>http://www.supergluetech.com/wp/2009/10/simple-round-function-for-perl/</link>
		<comments>http://www.supergluetech.com/wp/2009/10/simple-round-function-for-perl/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 18:27:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[math]]></category>

		<guid isPermaLink="false">http://www.supergluetech.com/wp/?p=5</guid>
		<description><![CDATA[A simple number rounding function for perl]]></description>
			<content:encoded><![CDATA[<p>Heres a usefull round function for Perl:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">sub</span> round <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@number</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span> <span style="color: #009966; font-style: italic;">/\./</span><span style="color: #339933;">,</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$precision</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span> <span style="color: #339933;">||</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #000066;">return</span> <span style="color: #0000ff;">$number</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">if</span> <span style="color: #339933;">!</span> <span style="color: #0000ff;">$number</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$decimal</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$number</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000066;">length</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$decimal</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&lt;</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$precision</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">return</span> <span style="color: #0000ff;">$number</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">$number</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$rounder</span> <span style="color: #339933;">=</span> <span style="color: #000066;">substr</span> <span style="color: #0000ff;">$number</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$precision</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$precision</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$rounder</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066;">return</span> <span style="color: #0000ff;">$number</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066;">return</span> <span style="color: #0000ff;">$number</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$base</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$number</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">'.'</span><span style="color: #339933;">.</span><span style="color: #000066;">substr</span> <span style="color: #0000ff;">$number</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$precision</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$rounder</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$rounded</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'.'</span><span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'0'</span> x <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$precision</span> <span style="color: #339933;">-</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #ff0000;">'1'</span><span style="color: #339933;">;</span>
		<span style="color: #000066;">return</span> <span style="color: #0000ff;">$base</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">$rounded</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000066;">return</span> <span style="color: #0000ff;">$base</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Usage is simple:</p>
<p>round( $number, $precision );</p>
]]></content:encoded>
			<wfw:commentRss>http://www.supergluetech.com/wp/2009/10/simple-round-function-for-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
