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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:42:53+00:00 2026-06-07T04:42:53+00:00

Here is a simple example: Dim si As Single For si = 2.6 To

  • 0

Here is a simple example:

Dim si As Single
For si = 2.6 To 3.3 Step 0.1
  MsgBox si
Next si

The numbers I get are as follows (they are shown below as they are displayed in the MsgBox):

2.6
2.7
2.8
2.9
3
3.099999
3.199999
3.299999

So, I figured I’d change the data type from Single to Double to see what happens. This time, there are no .099999 type numbers, but the last item (iteration) is skipped, as in, missing, and doesn’t exist. Here are the results as they appear in the MsgBox display):

2.6
2.7
2.8
2.9
3
3.1
3.2

I’m guessing in the case of the missing last iteration, it keeps track of it like the .299999 and never reaches .3 in its own mind, so skips it? However, the problem with this is that if this were happening, you’d get one of the previous iteration appearing twice for this to be able to happen, as it did in the Single Data Type example, where, if you truncated everything after the first decimal, you’d notice 3.0 appeared twice. First as “3” and then as “3.0” (if we ignore/truncate the 5 occurrences of the digit 9 after the “3.0” part – “3.099999”).

Interestingly, another function I have where I loop through something using the Single Data Type displays the exact problem that our Double Data Type example above has, and none of the problems our Single Data Type example above has. So, the real reason why I am here is my Single Data Type loop missing and skipping the last item when using “Step 0.1” (being incremented by 0.1).

Is there a reliable way to do this using a “Step 0.1” and non-integer data types? If not, do we know the rules by which these chaotic things occur (in that, is the chaos predictable)? sigh

I thought you would all find this interesting, and I sure am looking forward to understand it. Searching Google was useless since as soon as I entered the work “for” and “step” into it, kept bringing up samples on how to use the step operator and nothing useful.

I would be interested in knowing how to live with this, or do this safely, and/or why it is happening in the first place. I would rather not loop using Integers for this particular function (and then divide up using another variable to get my decimal types), however if I have to and there is no reliable way to do it otherwise, I will. But I leave this to you guys, my programmer overlords.

My examples were occurring in VB6, however, I’m also wondering if this same chaos is occurring in VB.NET and even in C#? I’m assuming it’s occurring in vba and vbscript. Any info on this would also be interesting and appreciated.

Thank you in advance.

To the Moderators (not necessary reading for the question): This is not a duplicate post, there may be other people posting floating-point issues in other languages (such as C#) but the solution to this (VB6) question is not necessarily the same as the solution for the C# question. There may be some solutions that are the same, but there will be solutions that are different as well, and there would be no way for me to get the different solution/answers from the C# post. As it turned out, the solution that I was interested in was a VB6 specific solution that would not have been found on the C# post that was referenced. I urge the mods to be diligent before attempting to close posts, I have seen post closed unfairly on many occasions and at the end of the day, you get to a stage where you are not adding any value, but removing substantial value from the Q and A style of this website. In conclusion, if there is even the possibility that there is new information/answers or solutions to be had by a similar looking post, you are better off refraining from closing. Especially if the questions are for a different language, even if the concepts are similar or the same, there are bound to be different solutions and solutions that are language specific.

  • 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-06-07T04:42:56+00:00Added an answer on June 7, 2026 at 4:42 am

    Try using a decimal instead for precision:

    For i As Decimal = 2.6 To 3.3 Step 0.1
      MessageBox.Show(i.ToString)
    Next
    

    If using VB6, you can try using the Currency type (as JeffSiver noted):

    Dim i As Currency
    For i = 2.6 To 3.3 Step 0.1
      MsgBox i
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't get past this issue I am having. Here's a simple example: class
here is a simple example to clear my intentions. class A { public int
This problem is not readily reproducible in a simple example here but was wondering
Possible Duplicate: Timezone conversion in php Here is a simple example of what i
I am learning and trying simple example using node.js and mongoskin. here is my
I'm studying webrat and cucumber and trying to create simple example. Here is my
I have a simple java project (adapted from the example here ), which is
Here is simple example I did: http://jsfiddle.net/J3rBX/ My purpose: when I mouseover that input,
Here's a simple example to illustrate the behavior: Given this html markup: <div data-company=Microsoft></div>
Here is a simple example; template <typename T> void foo(T t) {} std::string str(some

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.