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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:10:23+00:00 2026-05-28T18:10:23+00:00

In brief – I am having a hard time with the float left overs

  • 0

In brief – I am having a hard time with the float left overs
(i.e. 10.00000123 instead of 10)

Here I go :

I need to generate list of floats with constant gap as follows
(actually its a map , I need to retreive the object nut nevermind that)

List A: 0.25, 0.5, 0.75, 1, …
or
List B: 0.01, 0.02, 0.03, 0.04, …

every time I get a number and I round it to the neerest cell in the list.
lets say I get 0.051 to retreive a cell in list A – I return 0.05.
lets say I get 0.21 to retreive a cell in list B – I return 0.25.

So I started be doing this

float a = Math.round(Value / step) * step;

but than I get a lot of time 0.2500001 (float leftovers )
I need a smart way to round it .

Maybe by taking the number of digits after the dot and doing again

Math.round(Value / 100) * 100;?

Is there a smarter way?
I tried doig this

        final float factor = Math.round(1 / step);
        final float value = (float) Math.round(value * factor) / factor;

but I sometimes have a list like this

List A: 10, 15 , 20, 25, 30, …

and when I get 22 I retreive the cell of 20.
the problem is that When I get a gap of 10

Math.round(1 / baseAssetStep) 

returns 0 – and I get NaN

  • 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-28T18:10:24+00:00Added an answer on May 28, 2026 at 6:10 pm

    In short, “these are not the numbers you’re looking for.”

    Floating points are represented as binary fractional numbers, and some numbers that can be easily represented in base-10 (0.01, for instance) can’t be represented with a finite number of binary digits. This is similar to how 1/3 is easy in base 3 (it’s just 0.1), but requires an infinite number of digits in base 10 (0.333…).

    If you tried to represent 1/3 with a finite number of digits in base 10, you’d get an approximation. Similarly, if you try to represent 1/10 with a finite number of digits in base 2 (which is what float and double do), you’ll get an approximation, and similarly with 1/100. What you think is 0.01 in the code is actually a number that’s very close, but not exactly equal to, 1/100.

    There are many resources out there concerning floating points and the difficulty in working with them. http://floating-point-gui.de/ is a good place to start.

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

Sidebar

Related Questions

Here's the brief problem: Input: a list of strings, each containing numbers ( 3.4
Brief summary: I need a script/plugin for Firefox that selects the load next 25
Here are the brief definitions of encapsulation and abstraction. Abstraction: The process of abstraction
Brief question, beginner's work on Ruby/Rails. Here's my view: <h1>News</h1> <%= @posts.each do |post|
A brief description... I have 4 tables. contacts (a list of each person, unique
Brief description of requirements (Lots of good answers here, thanks to all, I'll update
A brief background: I'm working on a web-based drawing application and need to draw
In brief, I need to do something like this: I have a folder with
Here is a brief overview of what I am doing, it is quite simple
Brief background: I have two-step login page, which after step 1 sends one-time code

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.