Pular para o conteúdo principal
Versão: 10.4.1

ITLab.Template.DevPack.Structs

Provides immutable value structs for domain primitives requiring strict precision or type safety.

Componentes

TipoNomeResponsabilidade
StructRoundedDoubleImmutable double wrapper always rounded to 2 decimal places, with implicit conversions to/from double

Como usar

// Assign from a raw double — rounding is applied automatically.
RoundedDouble price = 19.999; // stored as 20.00

// Implicit conversion back to double for arithmetic.
double total = price * quantity;

// Safe equality comparison without floating-point drift.
Assert.Equal((RoundedDouble)10.005, (RoundedDouble)10.01);

O que não fazer

  • Do not use RoundedDouble for scientific or high-precision calculations that require more than 2 decimal places.
  • Do not bypass the struct by casting to double before performing comparisons.

Extensão pelo produto

  • Products can follow the same pattern to introduce other precision-controlled value structs (e.g. RoundedDecimal, PositiveInt).