ITLab.Template.DevPack.Structs
Provides immutable value structs for domain primitives requiring strict precision or type safety.
Componentes
| Tipo | Nome | Responsabilidade |
|---|---|---|
| Struct | RoundedDouble | Immutable 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
RoundedDoublefor scientific or high-precision calculations that require more than 2 decimal places. - Do not bypass the struct by casting to
doublebefore performing comparisons.
Extensão pelo produto
- Products can follow the same pattern to introduce other precision-controlled value structs (e.g.
RoundedDecimal,PositiveInt).