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

  • Home
  • SEARCH
  • 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 548933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:07:55+00:00 2026-05-13T11:07:55+00:00

While writing a test with a value that gets represented as a BigDecimal, I

  • 0

While writing a test with a value that gets represented as a BigDecimal, I ran into something weird and decided to dig into it. In brief, ‘0.00009’ when rounded to two decimal places is returned as 0.01 instead of 0.00. Really. Here’s my script/console capture:

>> bp = BigDecimal('0.09')
=> #<BigDecimal:210fe08,'0.9E-1',4(8)>
>> bp.round(2,BigDecimal::ROUND_HALF_DOWN).to_f
=> 0.09
>> bp = BigDecimal('0.009')
=> #<BigDecimal:210bcf4,'0.9E-2',4(8)>
>> bp.round(2,BigDecimal::ROUND_HALF_DOWN).to_f
=> 0.01
>> bp = BigDecimal('0.0009')
=> #<BigDecimal:2107a8c,'0.9E-3',4(12)>
>> bp.round(2,BigDecimal::ROUND_HALF_DOWN).to_f
=> 0.0
>> bp = BigDecimal('0.00009')
=> #<BigDecimal:2103428,'0.9E-4',4(12)>
>> bp.round(2,BigDecimal::ROUND_HALF_DOWN).to_f
=> 0.01
>> bp = BigDecimal('0.000009')
=> #<BigDecimal:20ff0f8,'0.9E-5',4(12)>
>> bp.round(2,BigDecimal::ROUND_HALF_DOWN).to_f
=> 0.0

Oh, and I get the same results if I use the default mode, like so:

>> bd = BigDecimal('0.00009')
=> #<BigDecimal:2152ed8,'0.9E-4',4(12)>
>> bd.round(2).to_f
=> 0.01

Here are my versions:

ruby 1.8.6 (2008-03-03 patchlevel 114) [i686-darwin9.2.2]
Rails 2.3.4

Has anyone seen anything like this?

  • 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-13T11:07:55+00:00Added an answer on May 13, 2026 at 11:07 am

    No, never seen this before, and it definitely looks like a bug. 0.00009 rounded to two decimal places should definitely be 0.00.

    The ROUND_HALF_DOWN should not change the behaviour since you’re not dealing with midpoint values.

    This link has more details.

    It seems to be a bug in the 1.8 levels that’s been fixed in 1.9. It’s a slightly bizarre one in that it only seems to affect numbers with an even number of zeros before the first non-zero digit and only if that digit is 5 or greater.

    That appears to be exactly your problem based on the data provided.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 336k
  • Answers 336k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer and I can't figure out how to draw the figure… May 14, 2026 at 3:45 am
  • Editorial Team
    Editorial Team added an answer I'd say it is mostly a backwards-compatibility measure, just like… May 14, 2026 at 3:45 am
  • Editorial Team
    Editorial Team added an answer This method assumes the words are only separated by spaces… May 14, 2026 at 3:45 am

Related Questions

I'm not brand new to the concept of unit testing but at the same
I'm really new to mocks and am trying to replace a private field with
I'm running into an unusual problem in my unit tests. The class I'm testing
Say one's writing a browser and wants to test it on many pages with
I've got a unit test I'm writing which seems to have some kind of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.