Toggle navigation
Home
▼ Details
Products and pricing
Chart gallery
User stories
Text analytics
CDC NAMCS Library
Blog
Tutorials
Contact
Sign in
Post Editor
← All help posts
View post
Save
## Rounding raw values <img src="/uploads/images/image-round-to-the-nearest-integer.png" alt="" style="max-width: 300px; margin: 0 auto; display: block;"/> ### Protobi rounds to the nearest integer Rounding to the nearest integer is a simple mathematical operation we apply to decimal numbers. For decimal numbers between two integers like 1 and 2 , rounding to the nearest integer is pretty straightforward. Decimals less than 0.5 are rounded down and decimals above 0.5 are rounded up. You may know this rule from elementary school-- "5 and above, give it a shove. 4 and below, let it go". ### How Protobi rounds half decimals For decimal numbers ending with exactly 0.5 there are two integers that are equally near. There are many different methods to handle rounding half numbers. For these cases, Protobi uses a convention called round half away from zero, where decimals ending with 0.5 are always rounded to the integer with the highest absolute value. This method is also known as round half toward infinity or commercial rounding because it is often used for currency conversions and price rounding. Rounding half away from zero treats positive and negative values symmetrically, and therefore is free of overall positive/negative bias. Some clients have remarked that decimals like 23.49999 should first round to one decimal 23.5 then round to 24. This is known as [double rounding](<https://en.wikipedia.org/wiki/Rounding#Double_rounding>) and we do not use this method when displaying raw numbers from your survey datafile. ## Rounding calculated values Protobi uses a slightly different method when rounding calculated values versus rounding raw values to account for the limited precision of arithmetic on computers. Protobi rounds to 6 decimals places first, then to your desired precision. ### Limited precision of arithmetic on computers Rounding errors occur on computers due to the limited precision of binary mathematics. Most decimal fractions cannot be represented exactly as binary fractions. This problem is easy to understand if you consider the fraction ⅓. You can approximate the decimal value to be 0.3, 0.33 or 0.333, etc. But no matter how many digits you write down you will never exactly represent ⅓. For instance in binary arithmetic 6/40 + 7/40 = 0.32499999999999996 which is close to but not exactly equal to 0.325. The value the computer returns is just an approximation of the original decimal fraction, and when rounded to the nearest integer the result would be 32%. But Protobi first rounds 0.32499999999999996 to 0.325000, so when rounded the integer result is 33%. Protobi rounds using the following method which covers a lot of cases where rounding errors occur due to the limited precision of binary arithmetic. <div class="helpjuice-accordion" data-controller="editor--toggle-element"><p></p><h2 class="helpjuice-accordion-title">Protobi rounding algorithm</h2><div class="helpjuice-accordion-body active" data-editor--toggle-element-target="body"><precode language="plain" precodenum="0"></precode><precode language="plain" precodenum="1"></precode></div><div class="helpjuice-accordion-toggle"></div><div class="helpjuice-accordion-delete"></div><p></p></div> ### Example of calculated decimals rounded to integers <figure class="table"><table><thead><tr><th style="text-align:center;">Decimal number</th><th style="text-align:center;">Rounded integer</th></tr></thead><tbody><tr><td class="xl63" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;width:65pt;" height="21" width="87" title="23.49">23.49</td><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;width:65pt;" height="21" width="87" title="23">23</td></tr><tr><td class="xl63" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="23.499">23.499</td><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="23">23</td></tr><tr><td class="xl63" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="23.49999">23.49999</td><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="23">23</td></tr><tr><td class="xl63" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="23.499999999">23.499999999</td><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="23">24</td></tr><tr><td class="xl63" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="23.5">23.5</td><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="24">24</td></tr><tr><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;width:65pt;" height="21" width="87" title="-23.5">-23.49</td><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;width:65pt;" height="21" width="87" title="-24">-23</td></tr><tr><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="-23.499999999">-23.499</td><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="-23">-23</td></tr><tr><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="-23.49999">-23.49999</td><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="-23">-23</td></tr><tr><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="-23.499">-23.499999999</td><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="-23">-24</td></tr><tr><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="-23.49">-23.5</td><td class="xl65" style="height:16.0pt;min-width:220px;text-align:center;text-overflow:ellipsis;" height="21" title="-23">-24</td></tr></tbody></table></figure> See the Wikipedia page for more information on [Rounding half away from zero](<https://en.wikipedia.org/wiki/Rounding#Rounding_half_away_from_zero>) and other rounding methods: - [Rounding half toward zero](<https://en.wikipedia.org/wiki/Rounding#Rounding_half_toward_zero>) - [Rounding half to even](<https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even>) - [Rounding half to odd](<https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_odd>) - [Logarithmic rounding](<https://en.wikipedia.org/wiki/Rounding#Logarithmic_rounding>) <!-- --> We can replace the rounding algorithm in your projects with your firm's business rules. Contact [support@protobi.com](<mailto:support@protobi.com>) for more information.
Publishing
Date
Status
Published
Draft
Slug
edit
Content
Thumbnail
Categories
Manage
New to Protobi?
Charts
Making Changes
Intermediate topics for editors
Frequently Asked Questions
SERMO Topics
Tutorial Pages
Internal Docs
Data Processing
Videos
Obsolete
GSG Admin
SERMO Admin
GSG Topics
How to...
Basics for viewers
Basics for editors
For project admins
Advanced topics
Assessments
Articles (in-progress)
New and updated articles
Process data in Protobi
superseded
Text open-end questions
Troubleshooting
Tracking studies
Organizing the view
API References
Tools
AI Database
Checking AI...
Convert to MD
Danger zone
Delete