maths

Discussion in 'Java' started by focode, Aug 29, 2008.

  1. focode

    focode Guest

    when i divide 5/2 in java i get 2.0 how can i get the exact value
    2.5 , actually i want to generate random number from 0 to 1 like .
    00987 , .09654 ........ pls any one reply me soon
     
    focode, Aug 29, 2008
    #1
    1. Advertising

  2. focode

    kapkan Guest

    focode пишет:
    > when i divide 5/2 in java i get 2.0 how can i get the exact value
    > 2.5 , actually i want to generate random number from 0 to 1 like .
    > 00987 , .09654 ........ pls any one reply me soon


    int five = 5;
    int two = 2;
    double result = five/twoint two = 2; // result = 2

    double result = (double)five/two // result = 2.5
     
    kapkan, Aug 29, 2008
    #2
    1. Advertising

  3. focode

    Guest

    On Aug 29, 12:47 am, focode <> wrote:
    > 2.5 , actually i want to generate random number from 0 to 1 like .
    > 00987 , .09654 ........  pls any one reply me soon


    import java.util.Random;

    Random rng = new Random();
    double randomNumber = rng.nextDouble();

    -Lucas
     
    , Aug 29, 2008
    #3
  4. focode

    kapkan Guest

    focode пишет:
    > when i divide 5/2 in java i get 2.0 how can i get the exact value
    > 2.5 , actually i want to generate random number from 0 to 1 like .
    > 00987 , .09654 ........ pls any one reply me soon


    int five = 5;
    int two = 2;
    double result = five/two // result = 2

    double result = (double)five/two // result = 2.5
     
    kapkan, Aug 29, 2008
    #4
  5. focode

    kapkan Guest

    focode пишет:
    > when i divide 5/2 in java i get 2.0 how can i get the exact value
    > 2.5


    int five = 5;
    int two = 2;
    double result = five/two // result = 2

    double result = (double)five/two // result = 2.5
     
    kapkan, Aug 29, 2008
    #5
  6. focode

    Roedy Green Guest

    On Thu, 28 Aug 2008 22:47:09 -0700 (PDT), focode
    <> wrote, quoted or indirectly quoted someone
    who said :

    >when i divide 5/2 in java i get 2.0 how can i get the exact value
    >2.5 , actually i want to generate random number from 0 to 1 like .
    >00987 , .09654 ........ pls any one reply me soon


    see http://mindprod.com/jgloss/floatingpoint.html
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Aug 29, 2008
    #6
  7. focode

    Roedy Green Guest


    >>when i divide 5/2 in java i get 2.0 how can i get the exact value
    >>2.5 , actually i want to generate random number from 0 to 1 like .
    >>00987 , .09654 ........ pls any one reply me soon


    also see http://mindprod.com/jgloss/pseudorandom.html
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
     
    Roedy Green, Aug 31, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ross Clement (Email address invalid - do not use)

    Maths expression drawing library

    Ross Clement (Email address invalid - do not use), Jan 11, 2006, in forum: Java
    Replies:
    4
    Views:
    618
    Vyacheslav Levitsky
    Oct 2, 2006
  2. Calum Maciver

    Maths Involved

    Calum Maciver, Feb 18, 2006, in forum: Java
    Replies:
    5
    Views:
    478
    Luke Webber
    Feb 19, 2006
  3. Andrew Bullock

    bit of a maths quesiton

    Andrew Bullock, Feb 5, 2005, in forum: C++
    Replies:
    2
    Views:
    325
    Victor Bazarov
    Feb 5, 2005
  4. Geoff

    Maths in HTML

    Geoff, Jan 4, 2007, in forum: HTML
    Replies:
    10
    Views:
    738
    Adrienne Boswell
    Jan 6, 2007
  5. Rory Campbell-Lange

    Maths error

    Rory Campbell-Lange, Jan 8, 2007, in forum: Python
    Replies:
    36
    Views:
    1,021
    Nick Maclaren
    Jan 16, 2007
Loading...

Share This Page