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 6955563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:45:10+00:00 2026-05-27T14:45:10+00:00

I want to count from 0.0001 to 1 with 0.0001 steps in ruby. I

  • 0

I want to count from 0.0001 to 1 with 0.0001 steps in ruby.
I wrote this code but it enters to an infinite loop. Somewhy the interpreter does a wrong summation.

x = 0.0001
while x != 1.0
  puts x
  x = x + 0.0001
end

Here is the first 10 value it gives:

0.0001
0.0002
0.00030000000000000003
0.0004
0.0005
0.0006000000000000001
0.0007000000000000001
0.0008000000000000001
0.0009000000000000002
0.0010000000000000002

It should be 0.0001, 0.0002, 0.0003, etc…
How can I make it working?
Thanks!

  • 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-27T14:45:10+00:00Added an answer on May 27, 2026 at 2:45 pm

    The problem is that real numbers in ruby are not represented exactly due to binary storage and manipulation. I would do this

    x = 1
    while x < 10000
        puts (x/10000).round(4)
        x += 1
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to fetch count from table per day but the time column is
I want to count data of each day from database using the for loop.
I'm not sure if this is possible but I want to count the number
I want to do SELECT count(*) FROM users where created_at within 3 days ago
I want to count the number of accounts from the resulting table generated from
I want to count the number of transactions which retrieves some reports from database
I want to find user tweet's count for each month from the time when
I want to convert : select convert(nvarchar(16), TimeLog, 120) requestTime, count(Request) As noOfQueries from
For example, I want to count from 001 to 100. Meaning the zero buffer
I want to print a range of numbers to STDOUT. But rather than count

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.