Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7508105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:37:16+00:00 2026-05-29T22:37:16+00:00

How can I round a floating point number to the nearest integer? I am

  • 0

How can I round a floating point number to the nearest integer? I am looking for the algorithm in terms of binary since I have to implement the code in assembly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T22:37:17+00:00Added an answer on May 29, 2026 at 10:37 pm

    UPDATED with method for proper rounding to even.

    Basic Algorithm:

    Store the 23-exponent+1’th bit (after the decimal point). Next, zero out the (23-exponent) least significant bits. Then use the stored bit and the new LSB to round. If the stored bit bit is 1, add one to the LSB of the non-truncated part and normalize if necessary. If the stored bit is 0, do nothing.

    **

    For results matching IEEE-754 standard:

    **
    Before Zeroing out the (23-exponent) least significant bits, OR together the (22-exponent) least significant bits. Call the result of that OR the rounding bit.
    The stored (23-exponent + 1) bit (after the decimal point) will be called the guard bit.
    Then zero out the (23-exponent) least significant bits).

    If the guard bit is zero, do nothing.

    If the guard bit is 1, and the sticky bit is 0, add one to the LSB if the LSB is 1.

    If the guard bit is 1 and the sticky bit is 1, add one to the LSB.


    Here are some examples using the basic algorithm:

    x = 62.3

        sign exponent             mantissa
    x =  0      5       (1).11110010011001100110011
    

    Step 1: Store the exponent+1’th bit (after the decimal point)

    exponent+1 = 6th bit

    savedbit = 0

    Step 2: Zero out 23-exponent least significant bits
    23-exponent = 18, so we zero out the 18 LSBs

        sign exponent             mantissa
    x =  0      5       (1).11110000000000000000000
    

    Step 3: Use the next bit to round
    Since the stored bit is 0, we do nothing, and the floating point number has been rounded to 62.


    Another example:

    x = 21.9

        sign exponent             mantissa
    x =  0      4       (1).01011110011001100110011
    

    Step 1: Store the exponent+1’th bit (after the decimal point)

    exponent+1 = 5th bit

    savedbit = 1

    Step 2: Zero out 23-exponent least significant bits
    23-exponent = 19, so we zero out the 19 LSBs

        sign exponent             mantissa
    x =  0      4       (1).01010000000000000000000
    

    Step 3: Use the next bit to round
    Since the stored bit is 1, we add one to the LSB of the truncated part and get 22, which is the correct number:

    We start with:

        sign exponent             mantissa
    x =  0      4       (1).01010000000000000000000
    

    Add one at this location:

    +                          1
    

    And we get 22:

        sign exponent             mantissa
    x =  0      4       (1).01100000000000000000000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I round a decimal number (floating point) to the nearest integer? e.g.
how can i round up a floating point number to the next integer value
I'm trying to convert a floating point number to binary representation; how can I
I was curious to know how I can round a number to the nearest
How can we round off a number to the nearest 10 in php? Say
How can I round a decimal number in Javascript to the nearest 10? My
How can i round a calculated mdx measure up to the nearest integer without
How can I round a number to the nearest X value (for example 50)
How can I round values to nearest integer? For example: 1.1 => 1 1.5
I want to round the following floating point numbers to the nearest 0.05. 449.263824

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.