943,626 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1067
  • Java RSS
Dec 28th, 2007
0

request and question in float random number

Expand Post »
Hi guys hope you fine
I have a request and question, for my request I would like from you to recommend me
which books and tutorials that I may follow help me to understand how to read and write files in java I really need to know that. and for my question is how to make a float random ends with five or zero only. For example 0.25 , 0.30 , 0.35 , 0.40 , 0.45 ,0.50 , 0.55 , and so on till number one. I don't need a float numbet appears to me such as 0.23 , 0.14 , 0.78 , 0.99 , 0.61 , 0.12 , etc ... so how it's done that


thanks,
my regard
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
alsoumhi is offline Offline
66 posts
since Aug 2007
Dec 28th, 2007
-1

Re: request and question in float random number

how about you just store it as an integer which when divided by 20 yields your number?
Reputation Points: 53
Solved Threads: 33
Posting Whiz in Training
bugmenot is offline Offline
224 posts
since Nov 2006
Dec 29th, 2007
0

Re: request and question in float random number

hi reading from file is not hard. <<Thinking java>> may give you some help.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Great_qiang is offline Offline
3 posts
since Dec 2007
Dec 30th, 2007
0

Re: request and question in float random number

I would do it as such. Assuming you want the floating number to be displayed to only 2dp.
  • I would first, generate an integer between 1-9, then divide it by 10.
  • Then I would have a second random function that generates either 0.05 or 0.0
  • I would then add the two together.

So for example:-

7 / 10 = 0.7
0.05
0.7 + 0.05 = 0.75
Last edited by iamthwee; Dec 30th, 2007 at 12:31 pm.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: i need help with GUI
Next Thread in Java Forum Timeline: java.sql.SQLException: Invalid column index





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC