Question

im having a problem on the results of the program that i'm developing.

Like for example if im having a number of 8672.59 and i would like to divide it into 2 the result should be 4336.295. The question is how can i convert it to a 2 digit decimal point both of them with rounding off the results so that i could still get the correct amount when i add the 2 numbers..

Example.

8672.59 / 2 = 4336.295

if rounded off to 2 digit digimal point the result is 4336.30

how can i convert it to 2 digit decimal point with out rounding off so that if it is multiplied by two the result would be the same as 8672.59 not 8672.60

Thank You!

Was it helpful?

Solution 2

Subtract the rounded result from the whole.

Dim Total as Double = 8672.59
Dim OneHalf = Math.Round(Total/2, 2)
Dim SecondHalf = Total - OneHalf

In your example, Total = 8672.59, so OneHalf = 4336.30 (rounded)

SecondHalf = 8672.59 - 4336.30 = 4336.29.

OTHER TIPS

If you want this operation to be reversible, you need to store enough information to back out the calculation. So, if you only store 8672.59 / 2 to two decimal places, you can't get 8672.59 back by multiplying by 2. You'll get either 8672.58 or 8672.60, depending on whether you stored 4336.29 or 4336.30.

Now, you can store the number to three decimal places (or whatever precision you need) and display only two of them. Just multiply the stored number by 2, and you get back your original number.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top