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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:31:03+00:00 2026-05-22T03:31:03+00:00

How to generate random numbers which will provide proper results on division (i.e the

  • 0

How to generate random numbers which will provide proper results on division (i.e the results should round to exactly 1 or 2 places after the decimal point).

(e.g a whole number by a decimal number providing decimal results – I have given a set of sample inputs below)

2827 by 2.5 = 1130.8
1747 by 0.8 = 2183.75
425 by 0.4 = 1062.5
935 by 0.8 = 1168.75
  • 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-22T03:31:04+00:00Added an answer on May 22, 2026 at 3:31 am

    It is worth noting that all integers can be divided by 0.4, 0.8 or 2.5 and be represented to two decimal places. This is because it is the same as multiplying by 2.5, 1.25, and 0.4


    However, if you have a divisor for which this is not true, you can do this in a loop.

    double divisor = 2.4;
    double factor = 100/divisor;
    Random rand = new Random();
    int maxValue = 1000;
    double ERROR = 1e-14*maxValue;
    
    for(int i=0;i<100;i++) {
    long randNum;
    do {
       randNum = rand.nextInt(maxValue+1);
        if (Math.abs(randNum * factor - (long) (randNum * factor)) > ERROR)
            System.out.println("reject "+randNum + " => "+randNum/divisor);
    } while(Math.abs(randNum * factor - (long) (randNum * factor)) > ERROR);
    System.out.println(randNum + " => "+randNum/divisor);
    

    prints

    729 => 303.75
    285 => 118.75
    84 => 35.0
    123 => 51.25
    999 => 416.25
    75 => 31.25
    reject 727 => 302.9166666666667
    reject 842 => 350.83333333333337
    504 => 210.0
    reject 368 => 153.33333333333334
    441 => 183.75
    579 => 241.25
    165 => 68.75
    

    This will generate random numbers until you have a number which is a multiple of 0.01.

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

Sidebar

Related Questions

I need to create a function that will generate 2 random numbers between x
What i need to do is create an app which will generate a random
I'm trying to create an android application which will generate random series of values
I want to generate random numbers manually. I know that every language have the
I want to generate random numbers from -n to n excluding 0. Can someone
How to generate random numbers using assembly code in the range 1--4 ?
I'm using srandom() and random() to generate random numbers in c on a Unix
What is the best way to generate random numbers using Objective-C on iOS? If
Like my question, i need to generate random numbers that have identical pairs between
How do I generate 30 random numbers between 1-9, that all add up to

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.