Also, stop thinking "double", think "decimal". If you don't see why try the
following:
Console.WriteLine("double test: " + (0.1d + 0.2d == 0.3d));
Console.WriteLine("decimal test: " + (0.1m + 0.2m == 0.3m));
And please, don't respond that this must be a bug in the way .NET implements
doubles, this is inherent to base 2 floating point arithmetics.
Bruno.
"Bruno Jouhier" <(E-Mail Removed)> a écrit dans le message de news:
4319668f$0$21299$(E-Mail Removed)...
> First, don't call it Double2 because
> * "double" is already a bad name for double precision floating point
> * your type will be a fixed-point decimal type, not a floating point base
> 2 type.
> So, Decimal2 would probably be a better name.
>
> Then, before embarking into the implementation of a new type, investigate
> if you could not use the standard decimal type, maybe with some static
> helper methods to perform the rounding operations that you need.
>
> If you really decide that you need a custom type, follow the other
> poster's advice, implement it as a struct. You can use a long for the
> value (your decimal value scaled by a factor of 100).
>
> And I recommend that you get good documentation on floating-point, fixed
> point arithmetics, the .NET decimal type and legal recommendations for
> rounding before you embark into implementing a new type.
> For an in-depth understanding of floating point types, my favorite page is
> http://docs.sun.com/source/806-3568/ncg_goldberg.html
> The .NET decimal type is documented in the on-line doc of Visual Studio.
> So, you don't have any excuse to not read it.
>
> Bruno
>
> <(E-Mail Removed)> a écrit dans le message de news:
> (E-Mail Removed)...
>> Hi,
>>
>> I have some problems with the default rounding method of C#
>>
>> check an earlier post of my :
>> http://groups.google.be/group/micros...10c5e788c35f06
>>
>> To create a workaround for this problem, I wan't to create my own
>> double type !
>>
>> the 'Double2' would act like a standard double but when assinging a
>> value to it, it will always my own rounding method to round the value
>> to 2 decimals.
>>
>> Double2 d = 1.235;
>>
>> d -> 1.23;
>>
>> How can I create my own type like this ?
>>
>> Kind regards
>> Frank Vandelinden
>>
>
>