Is there a way to stop vb.net from rounding?

I have a variable in a calculation with a decimal value of 0.222222222222 the format limits this to 4 decimal places so the result should be 0.2222 but the result ends up being 0.  Is there a way to make it display correctly (stop rounding)?
NevSoFlyAsked:
Who is Participating?
 
13ShadowCommented:
You are saying that the result variable type is decimal and you format it to only have 4 places, right?
The result variable and any other intermediate calculation variables would have to be decimal so the decimals are kept throughout the calculation.
Make sure the result variable is indeed of type decimal.

stackoverflow.com/questions/329957/truncate-decimal-number-not-round-off
0
 
Fernando SotoRetiredCommented:
Can you show us some code?
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
CInt (0.222222222222 * 10000) / 10000
0
 
Jacques Bourgeois (James Burger)PresidentCommented:
Good point from 13Shadow, but maybe it's not necessary

Since the result of a division is a Double, if you want to keep the value as a Decimal, then you can transform my solution to

CDec(CInt (0.222222222222 * 10000) / 10000)

However, since you want only 4 decimals, a Decimal value is overkill.
0
 
NevSoFlyAuthor Commented:
As It turns out one of the values was being converted into an integer as 13Shadow suggested I am going to use James' code snippet for now.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.