|
-
Apr 27th, 2005, 03:51 AM
#1
Thread Starter
Addicted Member
rounding problem
Hi,
Is there a way for rounding a decimal up or down? The vb .net Decimal.Round function always rounds to nearest.
VB Code:
Decimal.Round(123.456789, 4) = 123.4568
Home is where your Head is
-
Apr 27th, 2005, 07:23 AM
#2
Fanatic Member
Re: rounding problem
Just wanna try as no one answers
VB Code:
double d=double.Parse((123.456789).ToString("###,###0.0000"));
-
Apr 27th, 2005, 08:19 AM
#3
Hyperactive Member
Re: rounding problem
Just off the top of my head (actually pretty barren up there)
I think if you add or subtract 1/2 of the lowest digit's value, i.e. 0.5, you can force the round to round up/down.
e.g. to force 123.xxxxxxx to round UP to 4 decimal places first add 0.00005 before doing the round.
to force 123.xxxxxxx to round DOWN to 4 decimal places first subtract 0.00005
For 3 decimal places add/subtract 0.0005.
No guarantees, but give it a try and see if it does what you want.
DaveBo out
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
-
Apr 27th, 2005, 08:24 AM
#4
Re: rounding problem
NOTE: VB.Net does not round integers in the same way that VB6 used to.
See MSDN for specific functions.
I don't live here any more.
-
Apr 27th, 2005, 09:45 AM
#5
Re: rounding problem
 Originally Posted by kulrom
Perhaps I just haven't read enough this article .. only i found this by MSDN search engine and placed the link ... sorry, my mistake 
If you ignore the code samples, that article still contains relevant information.
I don't live here any more.
-
Apr 27th, 2005, 10:32 AM
#6
Re: rounding problem
Double - again!
Don't convert a nice precise datatype like DECIMAL to DOUBLE - never - please - never...
Ok - I feel better now.
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
|