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
Printable View
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
Just wanna try as no one answers
VB Code:
double d=double.Parse((123.456789).ToString("###,###0.0000"));
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
NOTE: VB.Net does not round integers in the same way that VB6 used to.
See MSDN for specific functions.
Quote:
Originally Posted by kulrom
If you ignore the code samples, that article still contains relevant information. :thumb:
Double - again!
Don't convert a nice precise datatype like DECIMAL to DOUBLE - never - please - never...
Ok - I feel better now.