|
-
Jan 1st, 2004, 02:26 PM
#1
Thread Starter
Fanatic Member
rounding to 2dp
there is a thread on the forums that is for vb6. i tried it and it doesnt work.
How is it possible to round to 2d.p?
i tried this:
Label8.Text = round(span.TotalMinutes * lblrate.Text)
the round word is highligted meaning its wrong
can anyone help?
-
Jan 1st, 2004, 03:00 PM
#2
Sleep mode
This for VB.NET !
VB Code:
Math.Round(decimal value)
-
Jan 1st, 2004, 03:00 PM
#3
Frenzied Member
-
Jan 1st, 2004, 03:05 PM
#4
Hi.
Use Math.Round.
Many of the functions found in VB6 is still available, but have been placed under different namespaces.
So all mathematical functions are found under the namespace Math.
Hope that made any sence...
Edit. Damn Mike. You made it just before I did...
I wish I could think of something witty to put in my sig...
...Currently using VS2013...
-
Jan 1st, 2004, 03:21 PM
#5
Thread Starter
Fanatic Member
math.round only gives me a whole value. Which means it rounds it up to the nearest whole value.
How is it possible to round it up to 2 decimal places?
-
Jan 1st, 2004, 03:23 PM
#6
Thread Starter
Fanatic Member
-
Jan 1st, 2004, 05:36 PM
#7
Frenzied Member
Side note.
Although I guess I understand the "rules" of rounding, logically this does not make sense to me:
VB Code:
MsgBox(Math.Round(42.5, 0)) ' Displays "42"
MsgBox(Math.Round(43.5, 0)) ' Displays "44"
But that's the design.
-
Jan 1st, 2004, 06:27 PM
#8
Member
Also there is math.ceiling which will round to the highest integer
ex. 12.1 would return 13
another cool one is math.floor
ex. 12.98 would return 12
-
Jan 1st, 2004, 06:30 PM
#9
Member
Originally posted by Mike Hildner
Side note.
Although I guess I understand the "rules" of rounding, logically this does not make sense to me:
VB Code:
MsgBox(Math.Round(42.5, 0)) ' Displays "42"
MsgBox(Math.Round(43.5, 0)) ' Displays "44"
But that's the design.
also your msgbox is legacy code for message box
it should be messagebox.show(and in here goes your stuff)
it is a overloaded procedure so its much more versatile then
msgbox.
-
Jan 1st, 2004, 10:42 PM
#10
Frenzied Member
Originally posted by Mike Hildner
Side note.
Although I guess I understand the "rules" of rounding, logically this does not make sense to me:
VB Code:
MsgBox(Math.Round(42.5, 0)) ' Displays "42"
MsgBox(Math.Round(43.5, 0)) ' Displays "44"
But that's the design.
Isn't that the rule of 'rounding towards even'? That's an IEEE standard.
Last edited by Lunatic3; Jan 1st, 2004 at 10:46 PM.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Jan 2nd, 2004, 09:56 AM
#11
Frenzied Member
Yes it is the rule. Just thought I'd point it out because it can make for some "gotchas" if you're not aware of it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|