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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:30:08+00:00 2026-06-11T08:30:08+00:00

I need to determine if a floating point number is a multiple of another

  • 0

I need to determine if a floating point number is a multiple of another floating point number using JavaScript.

I’ve read some other questions about floating point numbers and I’ve learned that they don’t work correctly with the modulo operator (%). I’ve also read that you can convert the floating point numbers to integers by multiplying by 10/100/1000, etc, but this doesn’t work correctly in all cases.

Example:

var A = 25.13;
var B = .0001;

var Value = A*1e5;
var Step  = B*1e5;

// Is Value a multiple of Step?
if(0 === (Value % Step)) {
// Do something
}

In this case, Value is a multiple of Step and it works correctly. But what about:

var A = 2.2;
var B = .0001;

It should be a valid multiple, but instead we get:

220000.00000000003 % 10 = 2.9103830456733704e-11

There’s an erroneous 3 in the 11th decimal position. I thought I could correct the problem with rounding with toFixed(), by doing:

var Value = (A*1e5).toFixed(10);
var Step  = (B*1e5).toFixed(10);

But if you do:

var A = 45436212356482;
var B = .0001;

You get:

4543621235648200192.0000000000 % 10.0000000000=2

It’s a valid multiple, but it thinks it isn’t.

With:

var A = 45436212546522156.45621565421;
var B = .0001;

This is not a valid multiple, but it thinks it is:

4.543621254652216e+21 % 10.0000000000=0

Is there a clever trick for determining if one floating point is a multiple of another? Or is this impossible?

UPDATE:

The goal is to restrict a number entered by a user (either integer or decimal) to certain increments.

  • If the Increment is 1, the user can enter 1,2,3,4,etc.
  • If the Increment is .5, the user can enter .5,1,1.5,2,2.5, etc.
  • If the Increment is .0002, the user can enter 1,1.001,1.0004,1.0006, but not 1.0001

From a logic perspective, a given value is or is not a valid multiple of a given increment.

  • 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-11T08:30:09+00:00Added an answer on June 11, 2026 at 8:30 am

    Given your last two examples, with 4543621235648200192 and such, it seems you want to accept numbers that are integer multiples of .0001 and reject those that are not and you want to do this not using .0001 but using a variable that contains the floating-point value nearest .0001.

    In general, that is impossible. There is no way for an algorithm to “know” that .0001 was intended when you pass it something else.

    If you restrict the problem more, a solution might be possible. For example, it is possible (perhaps not easy) to answer this question: Is the floating-point value X the floating-point value nearest to an integer multiple of .0001? (In other words, is there an integer k such that multiplying .0001 by k and rounding to the nearest floating-point value produces exactly X?)

    So, to get a solution, you need to describe your goal further. Do you want solutions for arbitrary values of Step or just certain values? Since binary floating-point cannot represent Step precisely enough, do you have some other way to describe it? E.g., will it always be a multiple of .0001? Is the Value you want to accept as a multiple always the binary floating-point number nearest an exact mathematical multiple, or might it have additional errors?

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

Sidebar

Related Questions

I need to Determine the serial port name connected to other machine using c#.
I need to determine the number of pages in a specified PDF file using
My winform application is launched by another application (the parent), I need determine the
I need to determine whether a string ( sourceString ) contains another string (
I need to determine if one class descends (directly or indirectly) from another. I
I need to determine which CSS should be applied on some specific pages. I
I need to determine location based upon N number of WIFI Access Points and
I need to determine if an image is above a certain brightness. Using a
I need to determine if an object already exists in an array in javascript.
I need to determine the size of a very large character-encoded file. A read

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.