Creating the Double2 type

  • Thread starter Thread starter FrankVDL
  • Start date Start date
F

FrankVDL

Hi,

I have some problems with the default rounding method of C#

check an earlier post of my :
http://groups.google.be/group/micro...ffbddf/a410c5e788c35f06?l=nl#a410c5e788c35f06

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
 
How can I create my own type like this ?

Create a struct with implicit conversion operators to/from double.

But is there any reason you're not using the Decimal type?


Mattias
 
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.
 
Back
Top