how to make a decimal a power of ten?

  • Thread starter Thread starter cody
  • Start date Start date
C

cody

I want to do some validation of data field something like the following:

System.Diagnostics.Debug.Assert(decimal.Truncate(this.GesamtPreis*100)==this
..GesamtPreis*100);

so that Iam sure that no more than a certain number of decimals are stored,
but I don't want to hardcode them I want that the user can set how many
decimals are stored?

I cannot use Math.Pow() since it works with double instead of decimal so I
have rounding errors.
 
cody said:
I want to do some validation of data field something like the following:

System.Diagnostics.Debug.Assert(decimal.Truncate(this.GesamtPreis*100)==this
.GesamtPreis*100);

so that Iam sure that no more than a certain number of decimals are
stored,
but I don't want to hardcode them I want that the user can set how many
decimals are stored?

I cannot use Math.Pow() since it works with double instead of decimal so I
have rounding errors.
Compare the decimal to the result of Decimal.Round.

David
 
cody said:
I want to do some validation of data field something like the following:

System.Diagnostics.Debug.Assert(decimal.Truncate(this.GesamtPreis*100)==this
.GesamtPreis*100);

so that Iam sure that no more than a certain number of decimals are
stored,
but I don't want to hardcode them I want that the user can set how many
decimals are stored?

I cannot use Math.Pow() since it works with double instead of decimal so I
have rounding errors.

Why don't you use "decimal.Round(x, NumberOfDigits) == x"? Wouldn't that do
what you want?

Niki
 
Back
Top