Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ Programming
➜ General
➜ Variables , arrays, float and int
Variables , arrays, float and int
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Robert Powell
Australia (367 posts) Bio
|
Date
| Sun 25 Jan 2004 09:55 AM (UTC) Amended on Sun 25 Jan 2004 09:58 AM (UTC) by Robert Powell
|
Message
| I have an array holding a bunch of floats, how would i take out one element, round it up or down to 2 decimal points , stip off the decimal points and move the data into an int variable, sort of like:
float new_array[5]
int some_int
if some_action then
new_array[0]= new_array[0]*some_defign
roundup new_array[0]
strip new_array[0]
some_int = new_array[0]_stripped
Please excuse my cruddy sudo code, oh also the data held in the array should still have the decimal points also could anyone recommend a webiste that has good information / tutorial on c programmin, im currently using the one on about.com and it hardly touches the things im delving into.
Thanks again in advance for all your helps. |
Just a guy having a bit of fun. Nothing more, nothing less, I do not need I WIN to feel validated. | Top |
|
Posted by
| Nick Gammon
Australia (23,158 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sun 25 Jan 2004 07:53 PM (UTC) |
Message
| You want a combination of "for each" to iterate through the array, "round" to round, and CInt to convert to an integer.
See this page for links to download the VBscript documentation:
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=2
The rounding would look something like this:
a = CInt (Round (a, 2)) |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
10,637 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top