I've had an idea for a class that, instead of storing a number as a single floating-point value, stores the exact value as two or more integers (in cases such as division, fractional exponents, or irrational numbers such as pi or e). The class would have it's own mathematical functions as methods, modifying the internal values and possibly storing additional values as needed, and returning a double. The point would be to always have the exact value, only rounding when returning a value. This sounds like a good idea to me, but i haven't seen it done before. Does it exist and i simply haven't seen it, or is there some inherent flaw with this idea?

Big Decimal still won't give an exact value for rational numbers such as 1/3, so your idea may still be useful if you store numbers as exact fractions.

It makes sense that a BigDecimal couldn't return a fraction, but it does store an exact value, right? The only reason i can think of for it having it's own arithmetic methods would be that it stores it's values in a different way that would allow for exact values, but doesn't work with the regular "a=b+c".

Apparently not! This extract is from the BigDecimal JavaDoc

In the case of divide, the exact quotient could have an infinitely long decimal expansion; for example, 1 divided by 3. If the quotient has a nonterminating decimal expansion and the operation is specified to return an exact result, an ArithmeticException is thrown.

It looks like it stores numbers as an arbitrarily long sequence of digits, with the decimal point anywhere. That means it can't store exact values for n/3, n/7 etc. So maybe there's still an opportunity for you here...

Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...

Hi I'm having a problem implementing a mini shopping cart drop down in the header to show the user all the products they have in their shopping cart. It seems the only solution for this is Ajax, and I've looked all over and can't find anything that I could possibly ...

Hi. Im using vb 2010. I want to dynamically add textboxes to my form by clicking on a button. I've google searched and so far this code worked:

Private Sub btn_addline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_addline.Click
Dim txtB1 As New TextBox
Dim i
For i = ...